Hey everyone I want create a tick but I am afraid of bugs and more.
This script seems like it has some problems cuz at the beginning it doesnt react:
Should I chooce another way cuz this seems like not working like I want?
local previous = tick()
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.A and pressA == false and tick() - Previous > CoolDown then
Previous = tick()
pressA = true
print("hey")
end
if input.KeyCode == Enum.KeyCode.D and pressD == false and tick() - Previous > CoolDown then
Previous = tick()
pressD = true
print("hey")
end
if input.KeyCode == Enum.KeyCode.S and pressS == false and tick() - Previous > CoolDown then
Previous = tick()
pressS = true
print("hey")
end
if input.KeyCode == Enum.KeyCode.W and pressW == false and tick() - Previous > CoolDown then
pressW = true
Previous = tick()
print("hey")
end
end)
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?
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.