Ok so basically i want to make something using a remote event that has a 0.5 seconds cooldown per player. Basically there is no point doing something about that in the local script since can be bypassed really easy so i am asking if its possible OnServerEvent to have that cooldown but per player and not a cooldown in general. Any ideas? Help is appreciated
1 Like
Maybe you want to have a debounce on the server script waiting for the remote event to fire?
local Event = game.ReplicatedStorage.Event --event you want to add debounce
local Debounce = 1 --secound to debounce
local DebounceForPlayer = {}
Event.OnServerEvent:Connect(function(player)
local CanceledForDebounce
if DebounceForPlayer[player] == nil then
CanceledForDebounce = false
elseif DebounceForPlayer[player]+Debounce >= tick() then
CanceledForDebounce = false
else
CanceledForDebounce = true
end
DebounceForPlayer[player] = tick()
if not CanceledForDebounce then
--some code
else
player:kick("You spammed too much!")
end
end)
2 Likes
i’d rather like to use tick as its more reliable imo.
local playerTable = {} -- create an empty table to store an index for everyone in
local someRemoteEvent = game.ReplicatedStorage.RemoteEvent-- an example event
local cooldownTime = 4 -- used 4 seconds as an example
game.Players.PlayerAdded:Connect(function(player)
if not playerTable[player.Name] then -- if there isn't an entry for the player already
playerTable[player.Name] = tick() -- Create a new entry in the table for each new player, and make the index their name so we can access it later
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if playerTable[player.Name] then -- if there's an entry of the player in the table
playerTable[player.Name] = nil -- remove it from the table
end
end)
someRemoteEvent.OnServerEvent:Connect(function(player)
if tick() - playerTable[player.Name] > cooldownTime then -- If the time is greater than the cooldown time (so if more than 4 seconds have passed since the last time you set the player's index in the playerTable to tick()
playerTable[player.Name] = tick() -- set it back to tick() so it resets
--CODE HERE
end
end)
7 Likes
You’re replying to me, isn’t it wrong?
Just to point out the reason i want this is to avoid someone firing the remote extremely quick and causing server lag. dolly when i used your code for some reason everytime when i fire it the 2nd time it kicks me even after 10 seconds. tacky your code worked perfectly fine. Thanks everyone for contributing <3
1 Like