hello so im having this problem with .Touched, it usually spams because the part that connects fastly disconnects and connects again (cos of it changing size/shape) so I was wondering on how to make it only do something once instead of multiple times.
✓ ANSWER ACCEPTED
How do I Prevent .Touched from spamming?
2 answers
✓ Accepted answer
I can provide an example:
local p = script.Parent
local x = true -- our debounce
p.Touched:Connect(function(hit)
if x then
x = false
-- your code
wait(5)
x = true
end
end)
As simple as that, if x isn't true, it won't run until x is true.
Good luck! If you have trouble inputting the debounce, feel free to ask me!
Wish you luck on your goal!
local object = script.Parent
local deb = false
local detime = 5 --debounce time
object.Touched:Connect(function(hit)
if deb == false then
deb = true
print("works!")
-- your code
wait(detime)
deb = false
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
use a boolean and if statement to prevent it from running a second time. #LazyAnswer
Try to make a boolean value and attatch it to, the statement, may you include the code you are currently using to possibly further help?
http://wiki.roblox.com/index.php?title=Debounce#Advanced_notation