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

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

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

✓ Accepted answer

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)

3 comments

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!

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.

0

Alright, thank you so much!

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