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

How do I make it so that when you click a brick there's a timer to teleport you?

Asked by 2 years ago
Edited 2 years ago

Hello! I wanted to know how to make a teleport brick that when you click a timer starts. By that i mean like, you click the brick and it teleports you after some seconds. I'm sorry, I'm not that good at scripting and I could not find help anywhere else. It's basically the last thing my game needs and i would really like to make it. Could anyone help me please?

1 answer

Log in to vote
0
Answered by
xXMadonXx 190
2 years ago
Edited 2 years ago

Easiest Method:

wait(seconds)

That stops the whole script for that amount of time though. If you need to let the script still do other things in that time, put it in a coroutine like so:

local timer = coroutine.create(function()
    wait(seconds)
end)

coroutine.resume(timer)

Edit: Added into your code for example and clarification (3 second timer)

With coroutine:

local tp = game.Workspace.TeleportPart1 
script.Parent.MouseClick:Connect(function(plr) 
    local waitForTp = coroutine.create(function()
        wait(3)
        plr.Character:MoveTo(tp.Position) 
        print(plr.Name," has teleported!") 
    end)

    coroutine.resume(waitForTp)
end)

Without coroutine:

local tp = game.Workspace.TeleportPart1 
script.Parent.MouseClick:Connect(function(plr) 
    wait(3)
    plr.Character:MoveTo(tp.Position) 
    print(plr.Name," has teleported!") 
end)
0
So, if i was using this script: local tp = game.Workspace.TeleportPart1 script.Parent.MouseClick:Connect(function(plr) plr.Character:MoveTo(tp.Position) print(plr.Name," has teleported!") end) where would i put this? Also, thanks for answering! hellmet1 42 — 2y
0
you connect Mouseclick to a function creating the coroutine and starting it. After the wait() inside the coroutine you teleport the player. I am going to edit the answer and import it into your code. xXMadonXx 190 — 2y
0
Alright, thank you so much! hellmet1 42 — 2y
Ad

Answer this question