HELP! Shutting down server BEFORE Teleporting

  1. What do you want to achieve?
    I made a lobby for my game, and I want it to teleport you to a sub game, where all the gameplay happens.
  2. What is the issue?
    When the lobby teleports you to the subgame, the server for the lobby shuts down before the teleport and it results in no teleport.

the teleporting script works I made a separate thread for that a while back and confirmed it works

This was not in studio since you cannot teleport in studio, I tested this in the game.

Please send the script.
[Character limit]

1 Like
local TeleportService = game:GetService("TeleportService")
local teleportID = 14627040487
local textLabel = workspace.Sign.Text.SurfaceGui.Frame.TextLabel
local zone = script.Parent --// the part encasing the floor pad
local timer = 30
local PlayerTable = {}

while task.wait(1) do
	PlayerTable = {}
	timer -=1
	print(timer)
	textLabel.Text = ("Boat Departing in "..timer)
	if timer == 0 then
		timer = 0

		local parts = workspace:GetPartsInPart(zone) --// get the parts inside of the zone
		for _, part in parts do
			local model = part:FindFirstAncestorOfClass("Model") --// check if the character model exists
			if model and model:FindFirstChildOfClass("Humanoid") then --// check if the model has a humanoid

				local player = PlayersService:GetPlayerFromCharacter(model) --// check if the character is a player
				if player and table.find(PlayerTable, player) == nil then
					table.insert(PlayerTable,player) --// add them to the table
				end

			end
		end
		if #PlayerTable > 0 then
			TeleportService:TeleportAsync(teleportID, PlayerTable) --// teleport them

		end
		
		task.wait(1)
		timer = 30 -- restart the cycle
	end
end

if you want to run code right before the game shuts down you can do something like this

game:BindToClose(function()
    local PlayerTable = game:GetService('Players'):GetPlayers()
	TeleportService:TeleportAsync(teleportID, PlayerTable)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.