Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I cant get anything to randomize a player into a team. Help pl0x?

I have tried doing this:

for i, v in pairs(game.Teams["Class-D"]:GetPlayers()) or (game.Teams["Mobile Task Force"]:GetPlayers()) or (game.Teams["Scientific Department"]:GetPlayers()) or (game.Teams["SCP-049"]:GetPlayers()) do

--Trouble part
end

I don't know what to add at the end to make it assign to a team.

1 comment

0

Player.Team = TeamObject

1 answer

This will randomize the player team. I didn't know your teams' colors, so you will have to change the color to the color of that team.


for _, v in ipairs(game.Players:GetChildren()) do

print(v)

local randomTeam = math.random(1,4)

if randomTeam == 1 then

v.TeamColor = BrickColor.new("Earth green") -- Change this to that team's color

elseif randomTeam == 2 then

v.TeamColor = BrickColor.new("Cashmere") -- Change this to that team's color

elseif randomTeam == 3 then

v.TeamColor = BrickColor.new("Medium blue") -- Change this to that team's color

elseif randomTeam == 4 then

v.TeamColor = BrickColor.new("Lapis") -- Change this to that team's color

end

end

I recommend using PlayerAdded, if you want it to run when the player joins.

game.Players.PlayerAdded:Connect(function(player)

local randomTeam = math.random(1,4)

if randomTeam == 1 then

player.TeamColor = BrickColor.new("Earth green") -- Change this to that team's color

elseif randomTeam == 2 then

player.TeamColor = BrickColor.new("Cashmere") -- Change this to that team's color

elseif randomTeam == 3 then

player.TeamColor = BrickColor.new("Medium blue") -- Change this to that team's color

elseif randomTeam == 4 then

player.TeamColor = BrickColor.new("Lapis") -- Change this to that team's color

end

end)

4 comments

0

this is a terribly inefficient way of doing this

0

a better way would to be using a dictionary of corresponding values

0

Whats the print for though?

0

The print?

This discussion is preserved as it was. New answers, comments, and votes are closed.