Also I want put long Tweens in there with my inputs so why should I use a
wait()?
Also I want put long Tweens in there with my inputs so why should I use a
wait()?
Oh sry I missunderstood something
If it’s on server then it’s impossible to exploit since clients don’t have access to the server scripts. Also what is the exact scenario your in?
but wait what If I want it to use in RunService
You could have a variable that represents a starting time. Whenever someone tries to use whatever has a cooldown, check if the current time - the start time is greater than the wait time. If it is, allow them to use it. An example may look like this:
local currentTime = tick()
local cooldown = 3
local function doStuff()
if tick() - currentTime >= cooldown then
currentTime = tick()
print("Cooldown is over")
end
end
Be careful with having your cooldowns relative to runservice if you dont use delta time. If your cooldown is decreased every frame, the higher the FPS, the faster the cooldown.
Like when I use it in loop or other then it will crash
while
— there happens a lot untill the debounce is false and the wait is finish
wait()
debounce = false
Can I use ur function with a if statement will it work?
It should, but it depends on your current implementation.
doStuff already does the if stuff
what do you mean you cant test it out in ur Studio??
Cooldown = 3
RunService.....
if debounce == true then
print("hey") -- prints(10000 times
wait(CoolDown)
debounce = false
end
end)
what???
Your method with debounce and wait() isnt a good Method
It will be stuck in Roblox Studio and crash it
did you put it in a while loop?
Again, your method is not working cuz I want a cooldown without any chrashes. If I would use it in a while loop or in a RunnService it will crash cuz untill the wait(CoolDown) ends it will print too many times “hey”
This is why I would not prefer
if pressed == true then
wait()-- time you want to wait
pressed = false
end
wait()
has its place, but it is thread-blocking and messy. I still would recommend you go with my original advice. Whenever someone tries to use something with a cooldown, check if enough time has passed for it to be allowed. This way it does not block any threads and is only called when it is needed.