Hi I was making a script where after the round everyone gets teleported to a random spawn. But with my script all it does it when the round is over they die can you help?
local spawns = {workspace.Part1.Position,workspace.Part2.Position,workspace.Part3.Position} for i, player in ipairs(game.Players:GetChildren()) do if player.Character and player.Character:FindFirstChild("Torso") then player.Character.Torso.CFrame = CFrame.new(spawns[i])
You describe your script as "teleporting each player to a random spawn". But that's not at all what it says (it doesn't use math.random
anywhere!)
Your script says:
For the i
th player
, teleport them to the i
th spawn.
There are only 3 spawns, which means the 4th player wouldn't have anywhere to go.
You should write what you actually said you wanted:
if player.Character and player.Character:FindFirstChild("Torso") then local randomSpawn = spawns[math.random(#spawns)] player.Character.Torso.CFrame = CFrame.new( randomSpawn ) end
Be wary that this will potentially "bunch up" a bunch of players in the same spawn.
laughablehaha's suggestion of MoveTo will help clean that up.
Use MoveTo, instead of CFrame. CFrame will still work, but will bunch up the players, like BlueTaslem said. MoveTo will fix that problem.