OnTeleport doesn't fully work?

I’m using OnTeleport to detect whether a player can do certain stuff, for example they can’t create a group if they are in the process of teleporting or can begin creating groups if the teleport has failed, however I am finding that OnTeleport only fires the RequestedFromServer.

Plr.OnTeleport:Connect(function(teleportState, placeId, spawnName)
	print("Teleport state chaged: ", teleportState)
	if teleportState == Enum.TeleportState.Started then
		print("Teleport started ("..Plr.Name..")")
	elseif teleportState == Enum.TeleportState.WaitingForServer then
		print("Teleport waiting for server ("..Plr.Name..")")
	elseif teleportState == Enum.TeleportState.InProgress then
		print("Teleport in progress ("..Plr.Name..")")
	elseif teleportState == Enum.TeleportState.Failed then
		print("Teleport failed! ("..Plr.Name..")")
	end
end)

Looking at the Dev Forum this appears to occur before, but there is no solution to it, is there a way to detect which state a players teleport is in?

Are you 100% sure that it gets the player as the “Plr” and it doesn’t think of “Plr” as nil?

That might be the issue, try using the OnTeleport event with a PlayerAdded event like this:

game:GetService("Players").PlayerAdded:Connect(function(Plr)
     Plr.OnTeleport:Connect(function(teleportState, placeId, spawnName)
        print("Teleport state chaged: ", teleportState)
        if teleportState == Enum.TeleportState.Started then
           print("Teleport started (" .. Plr.Name .. ")")
        elseif teleportState == Enum.TeleportState.WaitingForServer then
           print("Teleport waiting for server (" .. Plr.Name .. ")")
        elseif teleportState == Enum.TeleportState.InProgress then
           print("Teleport in progress (" .. Plr.Name .. ")")
        elseif teleportState == Enum.TeleportState.Failed then
           print("Teleport failed! (" .. Plr.Name .. ")")
        end
    end)
end)

If that’s the case then the script above will definitely fix your problem, try it and tell me what happens.

Nope still doesn’t work D: it still detects a change when it requests, but none of the other states.

I’m not sure why it doesn’t work for you but I will direct you to the Roblox Developer API Reference page of the Player.OnTeleport event here: Roblox Developer API Reference - Player.OnTeleport

1 Like