Teleporting to randomly selected map

Basically, there is multiple maps and I want to send all of the players to a randomly selected one. There will be no lobby, I would just like all of the players to spawn on one mal, then after a certain time (5 minutes) they will be transported to another map. They will fight for 5 minutes then teleport. Thanks.

1 Like

If there is no lobby, then you don’t need teleports.

Put SpawnLocations in all of your maps. Then every 5 minutes, put a random map into workspace. Then when players fall and respawn, they will spawn on the new map!

If you still need teleportation:

Use a for i, player in pairs(game.Players:GetPlayers()) do loop.
You can then get the player’s character and use char:MoveTo(pos)

To randomize it, at the beginning of the script type ‘os.time()’. Later when you need to randomize something, use the ‘math.random’ function.

Why would you need os.time()? All you need is math.random to pick a random map.

local maps = game.ServerStorage.Maps:GetChildren()
local randomMap = maps[math.random(1, #maps)]

To teleport the players to this map:

for i, player in pairs(game.Players:GetPlayers()) do
    local char = player.Character
    if char then
        char:MoveTo(spawnpointPosition)
    end
end

Where spawnpointPosition is the position of a randomly selected spawnpoint in the map.

You need os.time() because sometimes if you just use math.random it uses the same one over and over. Os.time() prevents that.

Really? I didn’t know that! Thanks for the info!
:heart: