I have been having some trouble recently, trying to make a system where, at the click of a gui button, it gets every player currently in the game, and assigns them each, a random role.
Currently, when this is run, the players all go onto the same team name for some reason, and on the server it shows that the players have a different team, compared to looking at their teams on the client. none of the teams have the “auto assignable” property set to true.
local rEvent = game.ReplicatedStorage.rEvents.rolesAssignment
local players = game:GetService("Players")
local teams = game:GetService("Teams")
rEvent.OnServerEvent:Connect(function()
for i,player in pairs(game.Players:GetPlayers()) do
if player then
if player.Team == nil then
local roles = teams:GetChildren()
local packLeader = teams.PackLeader
local randomTeam = roles[math.random(1, #roles)]
if #packLeader:GetPlayers() == 1 and randomTeam.Name == "PackLeader" then repeat
randomTeam = roles[math.random(1, #roles)]
until
randomTeam.Name ~= "PackLeader"
end
player.Team = randomTeam
print(player.Name.."is now in the team: "..player.Team.Name)
task.wait(2)
end
end
end
end)
i will link screenshots below as of what the script does currently. keep in mind, running these scripts were done on a local 4 player server, 3 players in the server returned the “tank” role, and 1 returned the “knight” role, none of which became villagers.
ive looked everywhere on developer forum, youtube and some community servers and nothing has worked.