Teleporting between places script error

As I said earlier, you have to use a debounce, without it, your game will crash.

You can also use this script:

local buttonPressed = false
 
script.Parent.Touched:Connect(function(hit)
    if not buttonPressed then

        buttonPressed = true
        -- stuff where teleport goes
        wait(3)
 
        buttonPressed = false
    end
end)

I used that, let me show you.


I think I did it right, but I don’t know.

Could you paste in the script here? It’s way easier.

local TeleportService = game:GetService("TeleportService")

local placeID_1 = 5720538856

local function onPartTouch(otherPart)
	if not bricktouched then
		bricktouched = true
	end
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if player then
		TeleportService:Teleport(placeID_1, player)
	end
end
script.Parent.Touched:Connect(onPartTouch)
local TeleportService = game:GetService("TeleportService")

local placeID_1 = 5720538856
local buttonPressed = false

script.Parent.Touched:Connect(
    function(hit)
        if not buttonPressed then
            local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
            if player then
                TeleportService:Teleport(placeID_1, player)
                buttonPressed = true
                wait(3)
                buttonPressed = false
            end
        end
    end
)

This will probably work in game. ^^

When I add this script, it underlines (with an orange line) otherPart, TeleportService and placeID_1

1 Like

As its giving error: cannot teleport in studio. Try using it in game it should work now.

Fixed that, just missed those variables.

Ah this works, let me publish this and try it in-game.

Yay! It worked. Thanks everyone for replying!

Awesome! Could accept my answer?