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

Whats wrong with my teleporting all players script?

Asked by 9 years ago

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])
0
Is there an error in the output? funyun 958 — 9y
0
no docrobloxman52 407 — 9y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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 ith player, teleport them to the ith 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.

Ad
Log in to vote
1
Answered by 9 years ago

Use MoveTo, instead of CFrame. CFrame will still work, but will bunch up the players, like BlueTaslem said. MoveTo will fix that problem.

Answer this question