Basically whenever a player wants to spam switch items with the inventory system I want to make it where there is a cooldown for that so lets say a player has a Scar and an AK or whatever I want a cooldown where if a player switches from a scar to AK he has to wait like a second or however long I can set it too before he can switch back to a scar or another gun
You should research roblox debounces
Add a debounce.
Char limit 30
How do I add debounce with the inventory?
A lot of people are saying “debounce”. While this is true, they’re not specifying how you would go about this. You’re not a beginner scripter, and I’m sure you know what a debounce is.
So, here’s my suggestion, this is a tick() debounce:
local debounce = tick()
local debounceTime = 1
if (tick() - debounce) > debounceTime then
-- Your code, switch weapon probably
debounce = tick()
end
This is a suggestion, tick() might be deprecated (I’m unsure).
I hope this helps you with your code!
Also, a bit of info on tick().
Tick basically gets the time passed since 1st January, 1970.
local debounce = tick() -- Stores that time in debounce
So, when you do:
(tick() - debounce) > debounceTime
You’re basically doing:
(Time passed - Stored time) > 1 second
I am a beginner scripter and I have no idea how to code lmao im only a builder sadly
That’s perfectly fine.
A debounce is essentially just a cooldown.
Think of it like this:
local debounce = true
if debounce then
debounce = false
-- code stuff (maybe a task.wait(1) as a delay)
debounce = true
end
The if statement will only run if debounce = true, so right after the if statement, we set the debounce to false to prevent spamming until the code has ended, hence we set debounce back to true at the end.
I hope my explanation wasn’t too complicated.
local debounce = false
local WaitTime = 1
while true do
if debounce == false then
debounce = true
print("test")
wait(WaitTime)
debounce = false
end
end
What script type should it be and where should I put it?
Where you placed your gun code
Oh alright the main code is obstruficated btw so would I need to do anything else?
No.
-------Roblox char limit------------