I Need help, i don´t know how to debouce this script, i saw that when i click too many times, the the barricade goes bad, it doesn´t do the wait(5) but when you click one time and you wait the 5 seconds it is normal, i want to do this because People can spam it and the wait(5) doesn´t respond well...

local isOn = true
local debouce = false

function on()
 isOn = true
 script.Parent.Transparency = 0
 script.Parent.CanCollide = true
end

function off()
 isOn = false
 script.Parent.Transparency = 0.8
 script.Parent.CanCollide = false
 wait(5)
  script.Parent.Transparency = 0
  script.Parent.CanCollide = true

end

function onClicked()

 if isOn == true then off() else off() end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

2 comments

0

I will be happy for a respond :D

0

Debounce is a way to block from certain things to be spammed repeatedly. All you have to do is to wrap the part you want to make debounce with if debounce == false then debounce = true --[[your code --]] wait(5) debounce = false--[[make sure the debounce gets off after certain seconds--]] end