Game crashing after TeleportService

I made a script that should teleport a player, who touched a teleport. In studio nothing strange happens, it just says: “Cannot teleport in Studio”. But when I play a game through Roblox Client, it just freezes. I am making a place in Team Create and the owner of this place says that everything working correctly and he is teleporting to a place without crash. I tried to find a solution on this site but nothing helped.

Here’s the teleport script:

local TeleportService = game:GetService("TeleportService")

script.Parent.Touched:Connect(function(hit)	
	
	local chr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if chr then
		game.Players[chr.Name].PlayerGui.ColorCorrect_WithoutFade.Disabled = false
		TeleportService:Teleport(5889038756, game.Players[chr.Name])
	end
	
end)
3 Likes

This question has been answered alot of times earlier too, although the problem might not be same but its worth checking them out rather than creating a new thread.

But as for the problem, it is probably because you don’t have a debounce after player is found.

Refactoring your script as such, should be a good fix:

local TeleportService = game:GetService("TeleportService")
local debounce = false

script.Parent.Touched:Connect(function(hit)	
    if debounce then
       return
    end

	local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Also you get the player instance from this function not the character.
	
	if player then
        debounce = true
		player.PlayerGui.ColorCorrect_WithoutFade.Disabled = false --This should be done with a Remote event on client side, but its fine for now.
		TeleportService:Teleport(5889038756, player)

        --Wait For Sometime.
        wait(5)
        debounce = false
	end
	
end)
2 Likes

I already tried to do this and also tried now but it doesn’t help.

Are you sure about it? Seems to be working fine for me. So thats all I can really help with this much information.

Maybe try increasing the debounce, and make sure you published the game.

It is working fine to me too when I am not in Team Create. When I use teleport in console for example, I am not crashing. I highlighted this for a reason. This may be the problem.

What do you mean by crashing, does Roblox Studio crash or does the output bar say cannot teleport?

This may be an intentional security feature by Roblox because of people abusing scripts similar to it in order to create clickbait games that just send you to another game. You should look into a few things that may set off red flags, like your game being marked as “may not work as intended”.

Roblox just freezes. And only solution is press Alt+F4.
@Turned_Away, My game has not any flags. The game owner can use teleports. And it don’t says “May not function as intended”.

What OS are you on & what are your specs?

Windows 10
Intel Core i3 M 370
RAM: 4 GB

Really weak computer but again, game is not crashing when I use teleport outside Team Create.

Try adding a value to every player that join and set the teleport value to false when player tries to teleport, so they only teleport once.
Try this:

local TeleportService = game:GetService("TeleportService")

script.Parent.Touched:Connect(function(hit)
	local chr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if chr then
		local player = game:GetService("Players"):WaitForChild(chr.Name)
		if player:FindFirstChild("CantTeleport") ~= nil then
			if player:WaitForChild("CantTeleport").Value == false then
				player:WaitForChild("CantTeleport").Value = true
				game.Players[chr.Name].PlayerGui.ColorCorrect_WithoutFade.Disabled = false
				TeleportService:Teleport(5889038756, game.Players[chr.Name])
			end
		else
			local val = Instance.new("BoolValue")
			val.Name = "CantTeleport"
			val.Parent = player
		end
	end
end)

I use this script for my game and it works.

local TeleportService = game:GetService("TeleportService")

local debounce = false

local placeID_1 = PlaceId

local function onPartTouch(otherPart)
	
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	
	if player and debounce == false then
		debounce = true
		TeleportService:Teleport(placeID_1,player)
		wait(5)
		debounce = false
	end
end

script.Parent.Touched:Connect(onPartTouch)