Roblox crashes when teleporting

So I am making a story game and sometimes when you are being teleported from the lobby to the main game, Roblox just freezes at the loading screen and stops responding…

This happens only to some people and rest of the people are successfully teleported to the main game, here is how they will see the people whose game is frozen

And here is what the person who froze will see.

Is there any way to fix it? Here’s my bus teleportation code…

local teleportService = game:GetService('TeleportService')
local players = game:GetService('Players')
local hitBox = script.Parent
local seats = workspace.Bus2:WaitForChild('Seats')
local status2 = workspace:WaitForChild('Status2')
local billBoard = status2:WaitForChild('BillboardGui')
local joinable = true
local busTable = {}

hitBox.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		for _, seat in pairs(seats:GetChildren()) do
			if seat.Occupant == nil and joinable and not table.find(busTable,player) then
				table.insert(busTable,player)
				hit.Parent.Humanoid.JumpPower = 0
				seat:Sit(hit.Parent.Humanoid)
				game.ReplicatedStorage.BusGui:FireClient(player)
				hitBox.PlayerCount.Value = #busTable
				break
			end
		end
	end
end)

game.ReplicatedStorage.BusLeave.OnServerEvent:Connect(function(player)
	local returnValue = table.find(busTable,player)
	if returnValue then
		table.remove(busTable,returnValue)
		player.Character.Humanoid.JumpPower = 50
		player.Character.Humanoid.Sit = false
		hitBox.PlayerCount.Value = #busTable
		wait(.4)
		player.Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame + Vector3.new(0,2,0)
	end
end)

hitBox.PlayerCount:GetPropertyChangedSignal('Value'):Connect(function()
	billBoard.Frame.Players.Text = 'Players: '..hitBox.PlayerCount.Value..'/6'
end)

coroutine.wrap(function()
	while true do
		for i = 30,0,-1 do
			if #busTable >= 6 then
				break
			end
			billBoard.Frame.Timer.Text = 'Time: '..i
			wait(1)
		end
		if #busTable < 1 then
			billBoard.Frame.Status.TextColor3 = Color3.fromRGB(255,0,0)
			billBoard.Frame.Status.Text = '2 Players needed!'
			wait(2.5)
			billBoard.Frame.Status.Text = 'Enter Bus'
			billBoard.Frame.Status.TextColor3 = Color3.fromRGB(17, 255, 0)
		else
			joinable = false
			billBoard.Frame.Status.TextColor3 = Color3.fromRGB(255,0,0)
			billBoard.Frame.Status.Text = 'Teleporting!'
			billBoard.Frame.Status.TextColor3 = Color3.fromRGB(62, 197, 255)
			local code = teleportService:ReserveServer(5839294170)
			teleportService:TeleportToPrivateServer(5839294170,code,busTable)
			for _, player in pairs(busTable) do
				game.ServerStorage.FadeUI:Clone().Parent = player.PlayerGui
			end
			repeat wait() until #busTable == 0
			billBoard.Frame.Status.TextColor3 = Color3.fromRGB(17, 255, 0)
			billBoard.Frame.Status.Text = 'Enter Bus'
			joinable = true
		end
	end
end)()

players.PlayerRemoving:Connect(function(player)
	local returnValue = table.find(busTable,player)
	if returnValue then
		table.remove(busTable,returnValue)
		hitBox.PlayerCount.Value = #busTable
	end
end)```
3 Likes

Maybe it’s just Roblox glitching, if not I can look into it. It seems that the script should work.

From experience I don’t think it’s the teleport I think it’s the game the player is being sent into.

It is probably because you have a loop that does not have a wait, and a script that has too big, or ,little of a loop.

1 Like

Oh yeah, I didn’t see that but yeah it’s probably the loop.

Also it might not be in that script.

Yeah I believe it’s a Script in the reserved server that he is being sent to.

I have had this issue before several times.

1 Like

Also if this solved it I’d suggest to mark the solved message so people know.

There are no loops that don’t have a wait in, because when testing in studio, you will get a Script timeout exhaustion limit reached, or something similar, we don’t get that.

1 Like

I also once had this problem but I luckily found the solution and its simple.

This problem occurs when one of the games that you are getting teleported into/out of, has their security settings turned off. Specifically, the “allow 3rd party teleports”.

To fix this, first go to your game settings.
Screen Shot 2020-10-21 at 18.44.06
Then go to security and enable 3rd party teleports.


Make sure you enable this for EACH place where you are using teleport service.

1 Like

These are already turned on for all the places of the game

1 Like

Hm, I don’t know what it is then. It’s probably some other scripts that is causing the error/ System failure.

I’m getting this exact problem. The first player teleports fine but any subsequent player gets stuck in a forever loading screen that freezes. It just randomly started happening. All my game settings are turned on so I’m really not sure if it’s on my end or Roblox’s. My teleports used to work before smh

EDIT* My problem was that my custom loading screen was blocking a roblox error message that I easily fixed once I knew what it was.

What was the thing? Maybe I have the same problem because I’m also teleporting with custom UI.

Try not using a custom loading screen, it may reveal a roblox message popup thats been hidden behind it the whole time. Not sure why the ZIndex of a custom loading screen is higher than a roblox kick message lmao… I guess we gotta delete the loading screen before kicking :stuck_out_tongue: