Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

team assigning script fails to run either from an "if" statement or when more than one player joins?

Asked by 4 years ago
Edited 4 years ago
-- assign plr to team
game.Players.PlayerAdded:Connect(function(plr)

--add to default team first
local defaultteam = game.Teams.TeamQueue.Name
if not plr.Team then
    plr:GetPropertyChangedSignal(defaultteam):Wait()
end
--



if plr.Team.Name ~= "TeamQueue" then
    print(plr.Name.."already in a team")
    return

elseif plr.Team.Name == "TeamQueue" then


    local teams = game:GetService("Teams"):GetTeams()
for _, team in pairs(teams) do
    local players = team:GetPlayers()

if #players <= 0 then
    plr.Team = team
    print(plr.Name.." assigned to "..team.Name)
    break
elseif #players >= 1 then
    return
end
end
end
end)
--

when I start a localserver, and then add players to it, the new players did not get assigned a team other than "TeamQueue".

1 answer

Log in to vote
0
Answered by 4 years ago

Add .Name after "if plr.Team"

Ad

Answer this question