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

How do you make a script that only 1 person joins a team and everyone else goes on the other?

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.

2 answers

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


2 comments

0

I find it easier to just use game.Players.NumPlayers.

0

That doesn't really have an effect on the the script works. It does the same thing, it just comes down to personal preference.

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