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.
local Front = script.Parent.Front local FrontDamaged = script.Parent.FrontDamaged local sound = script.Parent.Crash local debounce = false if not sound.IsLoaded then sound.Loaded:wait() end local function onPartTouched(otherPart) print(Front.Name .. " has touched " .. otherPart.Name) Front.Transparency = 1 FrontDamaged.Transparency = 0 sound:Play() end Front.Touched:Connect(onPartTouched)
TLDR: I need help putting a debounce so the part wont touch stuff multiple times at once.
I put comments where you add it.
local Front = script.Parent.Front local FrontDamaged = script.Parent.FrontDamaged local sound = script.Parent.Crash local debounce = false if not sound.IsLoaded then sound.Loaded:wait() end local function onPartTouched(otherPart) if debounce == false then --Here we check if it has been activated. print(Front.Name .. " has touched " .. otherPart.Name) Front.Transparency = 1 FrontDamaged.Transparency = 0 sound:Play() debounce = true --We set it to true so it can't be activated again. end end Front.Touched:Connect(onPartTouched)
Let me know if it worked!