function ToonsToBattle() local num = math.random(3) for i,player in pairs(game.Players:GetPlayers())do local torso=player.Character:FindFirstChild("Torso") if torso then if player.TeamColor == BrickColor.new("Bright red") then if num == 1 then torso.CFrame=TS1+Vector3.new(0,i*5,0) elseif num == 2 then torso.CFrame=TS2+Vector3.new(0,i*5,0) elseif num == 3 then torso.CFrame=TS3+Vector3.new(0,i*5,0) end end end end end
This script is a function that when called, we take everyone on the Bright red team and move each player to one of three spawns. What I want it to do is select a random spawn for each team member, but instead it selects one for all of them to be teleported to. I thought that making the value of 'num' local would have each player have it happen individually, but that didn't work. Some help with this?
The purpose of a for
loop is to do a block for each thing.
You don't define num
inside the for
loop, so it's not done for each.
If you want to do it for each, put it inside the loop.
Tab your code correctly!
Don't repeat yourself! If you find yourself writing code with variables like TS1
, TS2
, TS3
, that's usually a sign you should be using a list instead.
local num = math.random(#Spawns) torso.CFrame = Spawns[num] + Vector3.new(0, i * 5, 0)