Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Lobby teleporter with 20 second wait?

Asked by 4 years ago

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
Possibly use a debounce, I am new so I do not know much. Nicklaus_s 17 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
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>" boysharkdk 34 — 4y
1
I've fixed it. youtubemasterWOW 2741 — 4y
1
Hmm still doesn't seem to work. It's not even teleporting but it's printing "Teleporter1 Touched" boysharkdk 34 — 4y
1
It says this error Error: (20,4) Expected identifier when parsing expression, got ')' boysharkdk 34 — 4y
View all comments (2 more)
0
Try again. I've fixed it again. youtubemasterWOW 2741 — 4y
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 boysharkdk 34 — 4y
Ad

Answer this question