Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Lobby teleporter with 20 second wait?

I've been trying to make this Teleporter for my Lobby that teleports into the actual game but it doesn't seem to work

It has to work like this "The player walks on the platform" "It has a countdown on like 20" "after those 20 seconds are gone the player should teleport but if the player walks off the platform it shouldn't teleport Anybody got an idea for what I'm missing? Thanks I'm still pretty new to scripting

debounce = false

local TeleportService = game:GetService("TeleportService")
local gameID = 4975499287 
 
function onTouched(hit)
	if debounce == false then
		debounce = true
	print("Teleporter1 Touched")
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
	wait(20)
        TeleportService:Teleport(gameID, player)
    end
end
script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:Connect(function()
	if debounce == true then
		debounce = false
	end
end)

1 comment

1

Possibly use a debounce, I am new so I do not know much.

1 answer

Hello, shark! Try using a function that waits 20 seconds and then teleports the player as the function won't stop running after a player walks off the part. Try this:

local debounce = false

local TeleportService = game:GetService("TeleportService")
local gameID = 4975499287 

local function teleportPlayer(player)
	wait(20)
	TeleportService:Teleport(gameID, player)
end

local function onTouched(hit)
	if debounce == false then
		debounce = true
		print("Teleporter1 Touched")
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)

		if player then
			teleportPlayer(player)
		end
	end
end

script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(function()
    if debounce == true then
        debounce = false
    end
end)

6 comments

1

Hmmm Now it says this I've removed the ) at the end in line 09 as that was an error aswell but I don't know how to fix this one? "Error: (24,8) Expected 'end' (to close 'function' at line 21), got <eof>"

1

I've fixed it.

1

Hmm still doesn't seem to work. It's not even teleporting but it's printing "Teleporter1 Touched"

1

It says this error Error: (20,4) Expected identifier when parsing expression, got ')'

0

Try again. I've fixed it again.

0

Alright Now It teleports but it doesn't cancel the teleport once you walk off it. Should I try to make a if TouchEnded then Return else or? how

This discussion is preserved as it was. New answers, comments, and votes are closed.