Player teleportation

Thanks for everyone who helped me. I couldn’t make this without you guys! I finished my random map changing, round based script. I wanna expand on that. I want to make it so that players can wait in a lobby, then when the round starts teleport them to a new map. I have no clue how to approach this though. Can I maybe use local scripts, and probably use the human root part to teleport them? Can a remote function be used in this situation?

You can add small parts to the map that will be spawn points, where players will be teleported.

And then add them to a table using table.insert(table, value), for an i, v loop. Example:

for i, v in pairs (map:GetDescendants()) do
        if v.Name == "Spawn" then
        table.insert(table, v)
        end
end

And then teleport players through HumanoidRootPart by getting a random spawn, like:

local randomSpawn = table[math.random(1, #table)]
-- Table means the table where you inserted the spawns

And then teleport the players.

I understand. Thank you for the help!

So to start you’ll have to make a gui, or some indication of a timer. It’s not required but if you want the players to know how long till the round starts I suggest using it.
Roblox Status Bar Tutorial - Make An Intermission Bar! - YouTube
If you want help making it I suggest using this video.

Now to teleport everyone you’ll have to do something like this:

if Intermission =< 0 then
      for i, v in pairs (game.Players:GetChildren) do
               local player = v
               game.Workspace[player.Name]:MoveTo() -- Place you want them to go to in brackets
      end
end

It should be used on the sever script.

1 Like

Can you explain the script? Thanks though!

Sorry for the late reply, so what it does is it checks if the time (in seconds) is 0, Im assuming you have previous coding knowledge so you could store that as a variable. Sometimes however when your counting the seconds down it can go below 0 so you need to be aware of that.
Intermission =< 0 is checking if its greater or equal to 0 so it can start the code.

If the time is 0 or theirs no seconds left then it’ll look through all the children, in game.Players.GetChildren()
you could also do this for the workspace like
for i, v in pairs(game.Workspace:GetChildren())

Get children in this case is perhaps the most effective way to use but if needed you could use get descendants etc…

You can think it as a sentence. For every person in the game do this command or For every part in the workspace do this command etc…

image

For this it’d be for every descendant in the tool do something.

When it loops through the players (objects in the game.Players) it searches its name in the workspace. Players are normally stored as models in the workspace and models can be moved using the MoveTo() command.

Its like saying, “Okay so there’s a player called catplayer325r in the players, i want to get him from the workspace and move him to the part called spawn part”

MoveTo() Happily enough isn’t that complicated all it needs is a positional value (A position from practially anything,e.g(MoveTo(game.Workspace.Part.Position))) In this case you'd have to make a spawn of some sort and doMoveTo(game.Workspace.Spawn.Position)`
It almost always has to be a positional argument, if you wanted to move the player to a specific point then you could similarly do:

game.Workspace.Part:MoveTo(Vector3.new(0, 1, 0))

This’ll move them to those specific points on the x, y, z axis but I suggest the prior method.

if Intermission =< 0 then -- Checks if the time is equal or below 0 (Time should be stored in variable)
      for i, v in pairs (game.Players:GetChildren) do  --For every player do everything below
               local player = v   -- Assigns a variable
               game.Workspace[player.Name]:MoveTo() -- Checks the workspace for the players name and then moves the player to anything in the brackets
      end
end

I hope this helped

for _, v in pairs(game.Players:GetPlayers()) do
	game.Workspace[v.Name].HumanoidRootPart.CFrame = CFrame.new(Position to teleport to)
end

@KrampusX12 I thought you had to change the Model Primary Part Position in order to move it and not the model itself

Well yes, that would work equally aswell as would MoveTo() with there own pro’s and cons In this case I’d pick MoveTo as long as long as there isn’t anything on the spawn so the player doesn’t move to the top of whatever it is.