I'm making a murder mystery game but I don't know how to make 1 person join red team everyone else join the other team and after 120 seconds ( 2 minutes ) join the white team and then repeat i've had many attempts but none have worked..
my third attempt
local numPlayers = 0 for i, v in next, game.Players:GetPlayers() do if v:FindFirstChild("TeamColor") == BrickColor.new("Bright red") then numPlayers = numPlayers + 1 elseif v:FindFirstChild("TeamColor") ~= BrickColor.new("Bright red") then numPlayers = numPlayers - 1 end end if numPlayers == 0 then local player = game.Players:GetPlayers() local pickedPl = math.random(1, #player) pickedPl.TeamColor = BrickColor.new("Bright red") for i, v in next, game.Players:GetPlayers() do if v~=pickedPl then v:findFirstChild("TeamColor")=BrickColor.new("Team Color Name") end end end -- ... I think.
One error is that on line 18, "("Team Color Name")" Name it please else it looks like a free model. Second error the Bright Red team was always created Third Error is the rest of the players are on the out team Fourth error, theres no time limit Last Error, if the murderer dies it stays on the same team.
Well first of all instead of that big chunk to determine the number of players why don't you just use numPlayers = #game.Players:GetChildren()
Also in your script you tried to compare v (the player instance) to the random number you generated. Instead try:
randNumber = math.random(1, #game.Players:GetChildren()) for i, v in pairs(game.Players:GetChildren()) do if i == randNumber then pickedPL = v end end