I just tested a simple touched event with a TakeDamage and the humanoid takes damage several times quickly and dies, but only take that damage when they move. I know I can put a denounce but I don't want the function to be spammed repeatedly even with the debounce. I even tested this with changing the baseplate color to random and when I touched the part once, the baseplate changed several random colors in a second. Any ideas for the touched event to happen just once per touch?
Hello. The best option is Debounce. Your function will not be spammed. Here is an example:
Without Debounce
script.Parent.Touched:Connect(function() print("Hello World") end)
With Debounce
Debounce = false script.Parent.Touched:Connect(function() if Debounce == false then print("Hello World") Debounce = true wait(1) Debounce = false end end)
There is no optimal way to do that. Debounce is really your best option. However, you can disconnect the event if you wish. This makes it so that the event listener is turned off. This wiki page can explain some elements of a signal/event listener. It is relatively simple. Here is an example:
local connection -- here we name a variable but don't use it. You can name it what you like connection = script.Parent.Touched:Connect(function() -- does not have to be script.Parent. It will be whatever you are having be touched -- do whatever in here connection:Disconnect() -- this will turn off the event end)
If you have any additional questions feel free to post them in the comments under my answer.