The number it is printing is the amount of time since the last time it set the player’s debounce, you can see at the top it is working fine, but why does it break after a minute? (If it is less than 3 it prints hacker)
Code:
local cooldownTime = 6
local hasAuto = false
if player.OtherStats.Gamepasses:FindFirstChild("FasterHatching") then cooldownTime /= 2 hasAuto = true end
if tick() - petDebounce[player] < cooldownTime then
print(tick() - petDebounce[player])
print("Hacker")
return
end
print(tick() - petDebounce[player])
petDebounce[player] = tick()
your implementation of it may have an issue, a lot of games use that exact ratelimit and I ran a test for 2 minutes and it didn’t break (you only said a minute, so idk if you mean 60 seconds or an arbitrary amount of time)
local petDebounce = {}
openEgg.OnServerEvent:Connect(function(player,egg)
local cooldownTime = 6
local hasAuto = false
if player.OtherStats.Gamepasses:FindFirstChild("FasterHatching") then
cooldownTime /= 2
hasAuto = true
end
if not petDebounce[player] then
petDebounce[player] = 0
end
if tick() - petDebounce[player] < cooldownTime then
print(tick() - petDebounce[player])
print("Hacker")
return
end
print(tick() - petDebounce[player])
petDebounce[player] = tick()
print(("%s opened %s"):format(player.Name,egg))
end)
I figured out the issue, but I dont know how to fix it. This script below is the issue and is a local script.
UserInputService.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
if player.Character ~= nil and isHatching == false then
local nearestEgg
local plrPos = player.Character.HumanoidRootPart.Position
for i, v in pairs(Eggs:GetChildren()) do
if nearestEgg == nil then
nearestEgg = v
else
if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
nearestEgg = v
end
end
end
if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < maxDisplayDistance then
canHatch = true
else
canHatch = false
end
if canHatch == true then
local result = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("HatchOne"):InvokeServer(nearestEgg.Name)
if result ~= nil and result ~= "Max Storage" and result ~= "Not Enough Currency" then
if not cooldown then
cooldown = true
hatchOne(result[1],result[2], nearestEgg,result[3])
task.wait(0.1)
cooldown = false
end
elseif result == "Max Storage" then
print("Max Storage")
elseif result == "Not Enough Currency" then
print("Not Enough Currency")
end
end
end
UserInputService.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
if player.Character ~= nil and isHatching == false then
local nearestEgg
local plrPos = player.Character.HumanoidRootPart.Position
for i, v in pairs(Eggs:GetChildren()) do
if nearestEgg == nil then
nearestEgg = v
else
if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
nearestEgg = v
end
end
end
if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < maxDisplayDistance then
canHatch = true
else
canHatch = false
end
if canHatch == true then
local result = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("HatchOne"):InvokeServer(nearestEgg.Name)
if result ~= nil and result ~= "Max Storage" and result ~= "Not Enough Currency" then
if not cooldown then
cooldown = true
hatchOne(result[1],result[2], nearestEgg,result[3])
task.wait(0.1)
cooldown = false
end
elseif result == "Max Storage" then
print("Max Storage")
elseif result == "Not Enough Currency" then
print("Not Enough Currency")
end
end
end
What I noticed, was that when it said hacker when I was spamming, I noticed that right before it it printed common egg, so that means that result got ran, but either isHatching or cooldown was wrong.
Edit: when I removed cooldown it worked.