Hello, I making an Fps game so How do you add a cooldown/Delay so the players don't abuse the system there is an image button that's once pressed it shows up a Gui frame, the button scripting is quite simple
script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Frame.Visible = true end) --Please Note this is a **local script**
So how do you add a 30 secs or a minute cooldown until you can access it again?
and if the player tries to press the button while the button is in cooldown a script will play [Sound]
which is this game.SoundService.Barret_Equip.Playing = true
and when the button is NOT on cooldown the sound plays game.SoundService.Bell.Playing = true
Sorry if I am asking for too much
local debounce = false script.Parent.MouseButton1Click:Connect(function() if debounce == true then game.SoundService.Barret_Equip.Playing = true return else game.SoundService.Bell.Playing = true end script.Parent.Parent.Frame.Visible = true wait(30) -- change to 60 if you want it to be a minute debounce = false end)
This should be what you are looking for. The debounce is just a variable that is set as false originally, until it is first clicked. It is then set back to false after 30 seconds.
I recommend adding something called a debounce. It goes like this:
local debounce = false script.Parent.MouseButton1Click:Connect(function() if debounce == false then debounce = true script.Parent.Parent.Frame.Visible = true wait(30) debounce = false end end)
Anything you may wish to add to that, you can add before the "wait(30)" and after the "debounce = true"
Hope this helped!
Really easy to do! You can add a denounce and name it whatever you want! It basically stops the code from executing when it is running at a moment.
local debounce = false script.Parent.MouseButton1Click:Connect(function() if not debounce then -- Checks if debounce if false debounce = true -- Sets it to true script.Parent.Parent.Frame.Visible = true wait(2) debounce = true end end) --Please Note this is a **local script**