How do I add a 30 seconds debounce to this code?

I am trying to make a cool down thats 30 seconds long for this remoteevent keypress.
I suck at scripting. Any help??

My code:
local Player = game.Players.LocalPlayer
local UIS = game:GetService(“UserInputService”)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
game.ReplicatedStorage.TimeStop:FireServer()
end
end)

1 Like

You would debounce it like anything else really

Pseudocode

local last_press = tick()

when the button is pressed
    if tick() - last_press < 30 then
        return
    end
    last_press = tick()

Btw you might want to do a debounce on the servers since an exploiter can just remove the local debounce. Having both can work too

1 Like

Is this correct? Cause it didn’t work. I would like to keep it in the localscript.

local last_press = tick()

if tick() - last_press < 30 then
local UIS = game:GetService(“UserInputService”)

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
game.ReplicatedStorage.TimeStop:FireServer()
return
end
end)
end
(If this is wrong sorry I’m such a noob scripter)

No, you have it backwards

local last_press = tick()

local UserInputService = game:GetService(“UserInputService”)

UserInputService.InputBegan:Connect(function(input, game_processed)
    if game_processed or tick() - last_press < 30 then
        return
    end
    last_press = tick()
    if input.KeyCode == Enum.KeyCode.F then
        game.ReplicatedStorage.TimeStop:FireServer()
    end
end)
1 Like

This code you gave me doesn’t work. Btw I have my code in StarterGui as a local script. Is there another way this can be debounced?