So I made a tool where it spawns a brick but since I don't want people to spam it I wanted to put a debounce
I decided not to do it in the local script because if I did that exploiters can easily exploit it
So heres my Local Script
local Tool = script.Parent local Handle = Tool.Handle local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent Tool.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function()-- If Mouse is pressed RemoteEvent:FireServer() -- I fire Server end) end)
and my Server Script
local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent local CanFire = true local ReloadTime = 999 RemoteEvent.OnServerEvent:Connect(function(player) if CanFire == true then local part = Instance.new("Part") part.Parent = workspace CanFire = false wait(ReloadTime) CanFire = true end end)
The problem is that if one person fires this remote the other person cannot fire the remote and has to wait 999 seconds before firing again
I want it that each person can fire it without affecting other people
like Filtering Enabled
You can use a cool down time. This may be different than what you mean!
wait(5) --Waits 5 seconds
I personally solve this issue by using a table debounce for each player's userid, let me know if you have any questions:
local CooldownTimer=5 local OnCooldown={} local function Cooldown(UserId) OnCooldown[#OnCooldown+1]=UserId spawn(function() wait(CooldownTimer) for I=1,#OnCooldown do local CooldownedPlayer=OnCooldown[I] print(CooldownedPlayer) if CooldownedPlayer==UserId then table.remove(OnCooldown,I) end end end) end local function CheckIfOnCooldown(Player) local Passed=false for I=1,#OnCooldown do local CooldownedPlayer=OnCooldown[I] print(CooldownedPlayer) if CooldownedPlayer==Player.UserId then Passed=true end end return Passed end