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

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

Asked by
Prioxis 673 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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.

Ad
Log in to vote
0
Answered by
jav2612 180
10 years ago

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
0
I find it easier to just use game.Players.NumPlayers. systematicaddict 295 — 10y
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. jav2612 180 — 10y

Answer this question