I was thinking that if the exploiter fires a skill many times that is on cooldown then the skill will run,what I mean here is the exploiter can use the skill many times and then just keep spamming the skill while it’s on cooldown.How do I prevent this?
You should do cooldown checks not only on the client but also on the server.
how do I actually do that,do you have explainations?
By the way,I used an event so it’s Cilent-Server
One way you could do this would be to store a cooldown value on the Server as RoBoPoJu mentioned. You can implement this in many different ways, I use a RateLimit module for my projects, but for the purposes of simplicity sake, there is a simpler way to do this that doesn’t involve RateLimit modules/external code.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local myMainEvent: RemoteEvent = ReplicatedStorage:WaitForChild("AbilityEvent")
local abilityCooldowns: { [Player]: number? } = {}
myMainEvent.OnServerEvent:Connect(function(player: Player, argument: any)
local lastAbilityUseForPlayer: number? = abilityCooldowns[player]
if lastAbilityUseForPlayer then
if tick() - lastAbilityUseForPlayer <= 5 then -- this number can be whatever cooldown you want
return false -- ability is on cooldown
end
end
abilityCooldowns[player] = tick() -- we continue to the ability code and add time marker
-- code for ability etc....
end)
Players.PlayerRemoving:Connect(function(player: Player)
abilityCooldowns[player] = nil -- we do this to clean up the cooldowns
-- so we don't leak memory
end)
For each player, you can have a table that contains, for each skill, the last time they used the skill. When they fire the remote, you can check whether the difference between current time and that time is less than the cooldown time. The table of a spesific player should be stored in a table containing the tables of all players. When the player leaves, remove their table (playerSkillUseTimes[player] = nil
).
This suggestion is similar to the code @Charl_iey wrote although his code seems to assume that there’s only one skill.
Alternatively, for each skill, you can have a table that contains the players who currently have a cooldown for that skill. When the player fires the remote, check that they are not in the cooldown table. When the player succesfully uses a skill, do the following:
- Add them to the table of that skill (
playersWithCoolDownForThisAbility[player] = true
). - schedule the removal of the player from the table after the cooldown time (using
task.delay(coolDownTime, functionThatRemovesPlayerFromTable)
for example).
thank you,it worked and when I tried to fire the event,it kicks me out,ty!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.