When the player spawns in, there are 4 possible teams. The player is assigned correctly, but spawns on the wrong spawn sometimes. If the player is killed, they respawn at the correct one. How can I make the player spawning in wait until the team has been assigned, so they spawn on the correct spawn plate?
local function assignpla(player)
for r,t in pairs(game.Teams:GetChildren()) do
if #t:GetPlayers() == 0 or #t:GetPlayers() == nil then
local col = t --empty team
local qwe
for x,y in pairs(script.Parent.Tycoons:GetChildren()) do
if y.Name == col.Name then
qwe = y.Name
end
end
player.TeamColor = BrickColor.new(qwe)
end
end
end
I tried to put the player.TeamColor = BrickColor.new(qwe) after qwe = y.Name and then a break but it doesn’t break out of all the loops
Im not directly helping your issue, but you should write cleaner code for your own good in the later stages of development. This is a decent interpretation of what your code is supposed to do (I cannot really read it tbh, as you are abbreviating way too much):
local function assignTeamColor(player)
for _, team in ipairs(game.Teams:GetChildren()) do
if #team:GetPlayers() == 0 then
local matchingTycoon = script.Parent.Tycoons:FindFirstChild(team.Name)
if matchingTycoon then
player.TeamColor = BrickColor.new(team.Name)
end
player:LoadCharacter()
break
end
end
end
game.Players.PlayerAdded:Connect(function(player)
assignTeamColor(player)
end)
You can use player:LoadCharacter() to reset character silent
Code:
local function assignpla(player)
for r,t in pairs(game.Teams:GetChildren()) do
if #t:GetPlayers() == 0 or #t:GetPlayers() == nil then
local col = t --empty team
local qwe
for x,y in pairs(script.Parent.Tycoons:GetChildren()) do
if y.Name == col.Name then
qwe = y.Name
end
end
player.TeamColor = BrickColor.new(qwe)
end
end
player:LoadCharacter()
end
Perhaps you could turn off CharacterAutoLoads then when the TeamColor is assigned then you can use player:LoadCharacter() since there is no guarantee that the team will be set before the character is loaded.