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

Teleport Players to ordered spots?

Asked by 6 years ago
Edited 6 years ago

TLDR: How do I move players through the spots in the table making sure that it only teleports one player to one spot for each team?

So I am trying to make a script that will teleport players to ordered spots. I made a folder that contains the bricks I want to move them to, then turn it into a table with;

local spots = workspace.TipoffSpots.TeamOne:GetChildren()

Then I tried moving the players to the spots with;

local target = spots[math.random(1,#spots)]
player.Character:MoveTo(target.Position)

It works, but it sometimes moves players to the same spots when I don't want that to happen. How do I move players through the spots in the table making sure that it only teleports one player to one spot for each team?

1 answer

Log in to vote
0
Answered by
Pyracel 55
6 years ago
Edited 6 years ago

Alright, so for this we can use a for loop. I'll go ahead and give you the code.

By the way, you should use CFrame instead of MoveTo. This is not perfect, and it will not work if you have more players than spawns.

local spots = workspace.TipoffSpots.TeamOne:GetChildren()
local Players = game.Players:GetChildren() --Make sure this runs in a loop often, otherwise the player list won't be updated when another player leaves or joins.



for i, Spawn in pairs(spots) do 

if Players[i] ~= nil then

    local SelectedPlayer = Players[i]

    local SP= Spawn.Position --Makes it a little easier to read.


    if SelectedPlayer.Character ~= nil then

        SelectedPlayer.Character:WaitForChild("Torso").CFrame = CFrame.new(SP.X,SP.Y+5,SP.Z)

    end

end

end


0
Tyvm MmC00KIESmM 5 — 6y
Ad

Answer this question