Roblox Developer Hub-Funktion, um Rollen für die Gruppe zu erstellen, welche nicht in der originalen Gruppe sind: Wie nutze ich die Rollen in meinem Skript?

Hallo,

ich möchte ein Roblox-Spiel programmieren und brauche verschiedene Dienstränge von der Bundeswehr von meiner Gruppe in mein Roblox-Spiel connected. Das Problem ist jedoch: Roblox Studio erkennt diese Rollen vom Dev-Hub nicht und will die vom Spiel benutzen. Außerdem wird behauptet, ich sei kein Mitglied der Gruppe (obwohl ich der Creator/Owner bin). Kann mir jemand helfen?

Hier mein Skript, welches in der Programmiersprache Lua geschrieben ist:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local GroupId = 12242150 -- Replace with your Group ID

-- Define a table to map roles to teams
local RoleTeamMapping = {
  [1] = "Schütze",  -- Role ID 1 maps to Team1
  [2] = "Gefreiter",  -- Role ID 2 maps to Team2
  --Add more Roles and their corresponding teams as needed.
  [36] = "General",  -- Role ID 3 maps to Team3
}

-- Function to add player to the appropriate team based on their role
local function addPlayerToTeam(player)
  -- Check the player's role in the group
  local success, roleId = pcall(function()
    return player:GetRoleInGroup(12242150)
  end)

  if success then
    -- Check if the role ID exists in the mapping
    if RoleTeamMapping[roleId] then
      local teamName = RoleTeamMapping[roleId]
      local team = Teams:FindFirstChild(teamName)

      if team then
        player.Team = team
        print(player.Name .. " has been added to " .. teamName)
      else
        print("Team " .. teamName .. " does not exist.")
      end
    else
      print(player.Name .. " does not have a team associated with their role.")
    end
  else
    print("Failed to retrieve role for " .. player.Name)
  end
end

-- Connect the function to the PlayerAdded event
Players.PlayerAdded:Connect(addPlayerToTeam)

Dieses Skript ist als Basic Script in ServerScriptService gespeichert.

Kann mir jemand weiterhelfen?

Mit freundlichen Grüßen

Leland

Bild zum Beitrag
Code, lua, Programmiersprache, Roblox, Script, API, Roblox Studio

Meistgelesene Beiträge zum Thema Roblox Studio