Teleportation not working

So whats going on here is I wanted two things to happen in one script by combining two tutorials one would spawn the map the other would teleport players but when I mixed the scripts it changed nothing

The Tutorials

https://youtu.be/0CUSduKcCWk
https://youtu.be/DFQRXdMzEGg

The Code

local maps = game:GetService(“ServerStorage”):WaitForChild(“maps”)
local toAnnounce = game:GetService(“ReplicatedStorage”):WaitForChild(“toAnnounce”)
local gameModule = require(script:WaitForChild(“gameModule”))
local Game = game.Workspace.Game.Position

local minPlayers = 1

function clear()
toAnnounce.Value = “”
end

function announce(txt, duration)
toAnnounce.Value = txt
if duration ~= nil then
wait(duration)
clear()
end
end

function countdown(num, prefix)
for i = 0, num do
wait(1)
if prefix then
announce(prefix … num - i)
else
announce(num - i)
end
end
end

function startRound()

while #game:GetService("Players"):GetChildren() < minPlayers do
	announce(minPlayers .. " players are required to play...")
	wait(1)
end

wait(1)
countdown(3, "Round begins in... ")

local rand = math.random(1, #maps:GetChildren())
local allPlaces = maps:GetChildren()
local place = allPlaces[rand]

announce("Map chosen: " .. place.Name)
place.Parent = workspace
wait(3)

announce("Let the games begin!", 1)
gameModule.run(place)
local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i]:LoadCharacter()

end

countdown(3)
place.Parent = maps

end

– – – > PLAYER JOINS GAME

wait(5)
while true do
startRound()
end

normal script 1

local maps = game:GetService(“ServerStorage”):WaitForChild(“maps”)
local toAnnounce = game:GetService(“ReplicatedStorage”):WaitForChild(“toAnnounce”)
local gameModule = require(script:WaitForChild(“gameModule”))

local minPlayers = 1

function clear()
toAnnounce.Value = “”
end

function announce(txt, duration)
toAnnounce.Value = txt
if duration ~= nil then
wait(duration)
clear()
end
end

function countdown(num, prefix)
for i = 0, num do
wait(1)
if prefix then
announce(prefix … num - i)
else
announce(num - i)
end
end
end

function startRound()

while #game:GetService("Players"):GetChildren() < minPlayers do
	announce(minPlayers .. " players are required to play...")
	wait(1)
end

wait(1)
countdown(3, "Round begins in... ")

local rand = math.random(1, #maps:GetChildren())
local allPlaces = maps:GetChildren()
local place = allPlaces[rand]

announce("Map chosen: " .. place.Name)
place.Parent = workspace
wait(3)

announce("Let the games begin!", 1)
gameModule.run(place)

countdown(3)
place.Parent = maps

end

– – – > PLAYER JOINS GAME

wait(5)
while true do
startRound()
end

Normal Script 2 (not the main script)

local seconds = game.Workspace.Time
local ingame = game.Workspace.InGame.Value
local Game = game.Workspace.Game.Position

while true do

wait(1)
seconds.Value = seconds.Value - 1

if seconds.Value == 0 and ingame == 0 then

ingame = 1
seconds.Value = 20

local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i].Character:MoveTo(Vector3.new(Game.X, Game.Y, Game.Z))

end
end

if seconds.Value == 0 and ingame == 1 then

ingame = 0
seconds.Value = 15

local teleport = game.Players:GetChildren()
for i = 1, #teleport do
teleport[i]:LoadCharacter()

end
end

end

oh and the module script
(which is in the main script)

module script

local gameModule = {}

local function run(place)
	print(place)
	
end

return gameModule

I also have a save data script but I don’t think that’s very important
there is a object named game to have the teleport too

Thanks For Your Time.
P.S. maps is in server storage

Can you show the whole script please…? Like in ‘clean’ mode.

If there are more spawns than just the maps ones (if it has spawns in the first place) means it can select a random one, and ones that arent in the map. Im bad at explaining things so here is an example:

local Players = game.Players:GetChildren()

Maps = game.ReplicatedStorage.Maps:GetChildren()
 local SelectedMap = Maps[ math.random( #Maps ) ]
  SelectedMap.Parent = workspace

SelectedSpawn = SelectedMap.Spawns:GetChildren()

for _, Player in pairs(Players) do -- Go through everything in the players table
    if Player:IsA("Player") then --Check if it is actually a player
       Player:LoadCharacter() --Respawn
       if Player.Character then Player.Character:MoveTo(SelectedSpawn[ math.random( #SelectedSpawn ) ].Position + Vector3.new(0,1,0))
    end
end end

Here is a game file if you want that, the script is in serverscriptservice, its a bit messy.
Teleportation.rbxl (62.0 KB)

I updated my answer to have a random map selector aswell as spawn
i also forgot to mention you should keep maps in replicatedstorage instead of serverstorage as replicated storage is well, replicated to the server

1 Like

Thank you i’ll test it out. It looks like it should work.

1 Like

It didn’t work but I think I might have a fix but I might not.

Is the checking of the player necessary in the script? if it’s for extra maybe remove??

No but I just never took the time to take it out from the tutorial I was watching.

It works fine for me?
https://gyazo.com/3da17494eeb7ff53f3a1fabea4ede8fc

Can you put in the entire script so I can see where to put everything i’m a little new to Roblox lua, sorry.

Maps are put in a folder called Maps inside ReplicatedStorage, this can be seen in my example file. To add maps you just add a new model or folder inside the Maps one, you need to have a Spawns folder inside the map model/folder containing the parts you spawn at. Make sure the “Worker” script is in ServerScriptService, as poorly described as this is here is what it should look like:

image

The amount of maps you have doesnt matter it will pick a random one out of the things it finds inside the maps folder. Same with the spawns folder, if you have any more questions about it feel free to ask