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

Why is this script not giving players a team and no errors?

Asked by 7 years ago

How do i make players get a random team?

local teamColors = {BrickColor.new("Bright red"), BrickColor.new("Bright blue")}    
for i, user in pairs(game:GetService("Players"):GetPlayers()) do
if math.random(1, 2) == 1 then
user.TeamColor = BrickColor.new('Bright blue')
else
user.TeamColor = BrickColor.new('Bright red')
end
end

1 answer

Log in to vote
0
Answered by
itsJooJoo 195
7 years ago

Problem

You want to make a player get a random team

Solution

Use the PlayerAdded function to work this out with each joining player. Also remove the teamColors array because it seems to not be in use.

Final Script

--Function
function PlayerAdded(user)
    if math.random(1, 2) == 1 then
        user.TeamColor = BrickColor.new('Bright blue')
    else
        user.TeamColor = BrickColor.new('Bright red')
    end
end

game:GetService('Players').PlayerAdded:connect(PlayerAdded)

--Since studio changed the way PlayerAdded works, put these lines to make it work in Solo mode
for i, user in ipairs(game:GetService('Players'):GetPlayers()) do
    PlayerAdded(user)
end
Ad

Answer this question