Hey Developers! I have a question. It’s not for a specific script it’s just about the event in general.
For some reason, every time I use that function, it’s for when a player touches a brick. However, apparently, the event gets called about five or six times - the record being twenty-six - when a player touches a brick once. I want it so something happens once, within a time period (probably one or two seconds). I’ve tried a bunch of things to get around this but none of them seem to work.
What are your thoughts on this? What should I do the next time I have this situation? Thanks to whoever replies.
Typically called a “debounce” you need to ensure that the brick is called once by adding a delay to how often it can be called.
If you are trying to call it once, you simply do:
local Debounce = false
part.Touched:connect(function()
if p.Parent:FindFirstChild(“Humanoid”) and Debounce == false then
Debounce = true
– code
wait(any time you want before the next call)
Debounce = false
end
end)