Cooldown on Resetting

Hi all,

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?

Thanks in advance!

I did some more testing to find out what the problem is

onCooldown[plr] = true
print(onCooldown[plr])

Why on earth does that print nil???

1 Like

(sorry I didn’t explain this right lol)

I don’t exactly get what you mean. I’d appreciate if you gave me an example of how it should be.

1 Like

Yes, I’m currently working on it right now. Hold on.

1 Like

You can use a debounce feature.

Is this running on a gui? If it is. Will you show it to me?

It’s a localscript but the problem isn’t there

wait()
local resetBindable = Instance.new("BindableEvent")
resetBindable.Event:connect(function()
    game.ReplicatedStorage.ResetCalled:FireServer()
end)
 
game:GetService("StarterGui"):SetCore("ResetButtonCallback", resetBindable)

Can you be more specific, I want to know of what’re you attempting to accomplish I’m quite confused lol.

I want to know if it runs on a GUI or not :sweat_smile:

Like clicking buttons and stuff?

It’s in StarterPlayerScripts and it gets triggered when you reset

I get it, okay. Hold on give me a moment

That’s bizarre, nothing’s wrong with your coding. It looks good, Still I don’t get what the problem is.

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 :+1:

I appreciate everyone who tried to help.

they can what??? :joy: :joy:

Edit: If the exploiter fires the remote event through exploits, it’s literally the equivalent of pressing reset.

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