Where do I insert debounce into my script so the part wont trigger the function multiple times?
Lets say I have 2 parts. Front, and FrontDamaged. My script makes Front transparent, and FrontDamaged not transparent, whenever Front touches another part. It also plays a sound when it touches something. The thing is, it has no cooldown. And im stuck on where to add the debounce at.
01 | local Front = script.Parent.Front |
02 | local FrontDamaged = script.Parent.FrontDamaged |
03 | local sound = script.Parent.Crash |
07 | if not sound.IsLoaded then |
11 | local function onPartTouched(otherPart) |
12 | print (Front.Name .. " has touched " .. otherPart.Name) |
13 | Front.Transparency = 1 |
14 | FrontDamaged.Transparency = 0 |
19 | Front.Touched:Connect(onPartTouched) |
TLDR: I need help putting a debounce so the part wont touch stuff multiple times at once.