This is for a randomizer game im working on but when i use this code it just doesnt work
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if player and player.TeamColor == game.Teams.Playing.TeamColor then
for i = 1, 4 do
local rantool = tools:GetChildren()[math.random(1, #tools:GetChildren())]:Clone()
rantool.Parent = player.Backpack
print(player.Name.." got "..rantool.Name)
end
end
end)
end)
In these cases I would usually print out any variables I am comparing to see why exactly it doesn’t work.
if player and player.TeamColor == game.Teams.Playing.TeamColor then
for i = 1, 4 do
local rantool = tools:GetChildren()[math.random(1, #tools:GetChildren())]:Clone()
rantool.Parent = player.Backpack
print(player.Name.." got "..rantool.Name)
end
else
print(player.TeamColor)
print(game.Teams.Playing.TeamColor)
end
If the player team color returns as nil or a default one then from that information I would understand that the code runs before any team has been assigned.
Then I would also be sure if the game.Teams.Playing.TeamColor variable is correct.