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

How to stop multiple touches?

I'm currently working on a teleporter [like the one in flood escape] for a racing game. Where when you touch the invisible barrier it puts you inside the teleporter then adds your name in an array so the script can teleport you when the race starts. The problem is when the player touches I have it print ("Touch"), so in the output it prints: Touch(x30). I've tried a couple if statements so it will only fire touch once but nothing seems to work.

Heres the code:

Pa = {}

script.Parent.Touched:connect(function(part)
print("Touch")
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
table.insert(Pa, part.Parent.Name)
local root = part.Parent:FindFirstChild("HumanoidRootPart")
root.CFrame = script.Parent.Parent.Parent.MovingParts.Platform.CFrame + Vector3.new(0,5,0)
wait()
end
end)

Any idea's would be greatly appreciated.

3 comments

0

Check out this great Roblox Wiki article: https://developer.roblox.com/articles/Debounce

0

Thank you!

0

I tested it out and it works, the table only has one value in it. Thank you so much.

1 answer

✓ Accepted answer

Use a debounce, basically what it is, is just like a cooldown, set a boolean value called DB and make it false and when the touch event gets triggered, make an if statement seeing if DB == false then and then do DB = true

1 comment

0

Please read the op. That has already been suggested

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