Server-Side Cooldown Affecting All Players

I have a bug where in my “Shovel” tool, there is a server cooldown. When I dig with it, it works. But when I dig while someone else digs it doesn’t work. Im positive this is a cooldown issue on the server. I have tried Bindable functions, Delay, and Spawn. I use a table to store the players in the cooldown.

The table is called “ShovelCooldown”

instead of adding/removing the player from the table, you can simply do

local cooldownTable = {}
cooldownTable[plr.Name] = true

if cooldown[plr.Name] then
   return
else
   --do stuff
   wait(2)
   cooldown[plr.Name] = false
end

Would this go in the beginning of the script? And what does return do?

This might not be exactly what you’re asking for, but if I were making this system, I would keep everyone’s last dig time in a table that you can reference at any time. No need to add/remove them from the table multiple times in a session.

local shovelCooldowns = {}
local cooldownTime = 5

local digEvent = Instance.new("RemoteEvent")
digEvent.Name = "DigEvent"
digEvent.Parent = game.ReplicatedStorage

game.Players.PlayerAdded:connect(function(player)
    shovelCooldowns[player] = 0
end)

game.Players.PlayerRemoving:connect(function(player)
    shovelCooldowns[player] = nil
end)

digEvent.OnSeverEvent:connect(function(player)
    local lastUse = shovelCooldowns[player]
    if tick()-lastUse < cooldownTime then
        return
    else
        shovelCooldowns[player] = tick()
        -- dig!
    end
1 Like

this is just an example of how you would make a cooldown system and return just stops the script there if the cooldown is active