I’ve been working on a randomizer type game where you get a random set of weapons eveytime you respawn. In order to avoid people spamming reset to reroll their inventory, I’ve decided to add a cooldown on Resetting.
Here’s the code:
local onCooldown = {}
game.ReplicatedStorage.ResetCalled.OnServerEvent:connect(function(plr)
if plr.TeamColor == game.Teams.Thieves.TeamColor then
[...]
end
if plr.TeamColor == game.Teams.Police.TeamColor then
print(onCooldown[plr])
if onCooldown[plr] == nil then
if plr and plr.Character and plr.Character.Humanoid.Health > 0 and not plr.Character:FindFirstChild("ArrestInProgress") then
plr.Character.Humanoid.Health = 0
onCooldown[plr] = true
wait(30)
onCooldown[plr] = nil
end
else
game.ReplicatedStorage.ClientNotify:FireClient(plr, "Reset", "Reset is on cooldown! (30s)", "rbxassetid://149260272")
end
end
end)
In order to figure out what the problem was, I tried to print the player’s cooldown and surprisingly it always returns nil which means I can spam reset (the character dies but the cooldown remains nil.) Could anyone figure out where I went wrong?
local onCooldown = {}
game.ReplicatedStorage.ResetCalled.OnServerEvent:connect(function(plr)
if plr.TeamColor == game.Teams.Thieves.TeamColor then
[...]
end
if plr.TeamColor == game.Teams.Police.TeamColor then
print(onCooldown[plr])
if onCooldown[plr] == nil then
if plr and plr.Character and plr.Character.Humanoid.Health > 0 and not plr.Character:FindFirstChild("ArrestInProgress") then
plr.Character.Humanoid.Health = 0
onCooldown[plr] = true
coroutine.wrap(function()
wait(30)
onCooldown[plr] = nil
end)()
end
else
game.ReplicatedStorage.ClientNotify:FireClient(plr, "Reset", "Reset is on cooldown! (30s)", "rbxassetid://149260272")
end
end
end)
can u try this?, also why not just use the characteradded event instead of a remotevent?
made this real quick u shoud just use characteradded instead cause exploiters can disable remotevents.
local onCD = {}
game.Players.PlayerAdded:Connect(function(Player) -- get the players that joined
Player.CharacterAdded:Connect(function(Char) -- fires everytime the character loads
if not onCD[Player] then -- we check if player isn't on the list
onCD[Player] = true -- add if not.
print("Added Player on the List.")
coroutine.wrap(function()
wait(10)
onCD[Player] = nil -- we remove the player after 10 seconds
print("Player Removed from the list")
end)()
else -- if the player is found in the list
warn("Player already on the list!") -- then we print this.
end
end)
end)
Hey, I’d suggest you work on disabling the reset system entirely.
Why do I think that:
I feel like it would encourage the user to get involved instead of just resetting constantly to get a tool, even if there was a cooldown.
It would stop people from resetting if your system has a leaderboard system: E.G: Kills/Deaths
If you do want to keep the system, I would advise working on a reset UI with a cooldown and disabling the roblox system reset to comprimise.
(IF THAT IS EASIER)
If - EnigmaticDevil’s suggestion works then ignore this reply.
Hey, it turns out the problem was actually inside this excerpt of the code. The rest works perfectly well. Pretty embarrassing if you ask me. The code I’ve shown had no flaw to begin with… but now I got it fixed
Yes, exploiters can disable remotevents from being fired, but I guess that doesn’t really do anything besides not giving them weapons I guess?. Yea but wouldn’t that be critical? like he’s running then suddenly swapped weapon, idk whatever type of game that is for xd