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

How To Make Teleport Pads Teleport Only Once?

Asked by 5 years ago
Edited 5 years ago

Hello, I am new to scripting and would like to know how to make teleport pads only teleport once. So if you stand on a teleport pad,you won't teleport back and forth.

local Teleport = "Lentilkac58-Easy-Teleport-2"
function Touch(hit)
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
local Pos = script.Parent.Parent:findFirstChild(Teleport)
hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end
script.Parent.Touched:connect(Touch)
0
It's called a debounce. DeceptiveCaster 3761 — 5y
0
^ Creacoz 210 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

To do this, you'll need to set a debounce and never change it back so it only works once ;)

Try this:

local Teleport = "Lentilkac58-Easy-Teleport-2"
local Debounce = true -- Debounce is here
function Touch(hit)
if not Debounce then return end -- If Debounce is false this won't work
if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
local Pos = script.Parent.Parent:findFirstChild(Teleport)
hit.Parent:moveTo(Pos.Position) 
Debounce = false -- Set debounce to false so it won't work no more after teleporting
wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false end end
script.Parent.Touched:connect(Touch)

Hope this helped! Best of luck developer!

0
Thank you, it’s very appreciated! LightSunset 6 — 5y
Ad

Answer this question