Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Do I Give This Item A Recharge Time?

So, i made a item that when heals you when you use it, but i dont know how to give it a recharge time, you can just spam click it and instantly heal yourself. This is the script that i used:

local tool = script.Parent

tool.Activated:Connect(function()
	local humanoid = tool.Parent:FindFirstChild("Humanoid")
	humanoid.Health = humanoid.Health + 15
end)

1 answer

✓ Accepted answer

You should use simple debounce, a value that will be set to false whenever you heal yourself and then be set back to true after your desired time, in your case it would look like this

local tool = script.Parent

local DebounceTime = 5 -- seconds
local debounce = false

tool.Activated:Connect(function()
	
	--/If debounce is active, don't heal
	if (debounce) then
		return
	end

	local humanoid = tool.Parent.Humanoid
	humanoid.Health += 15

	debounce = true

	wait(DebounceTime)

	debounce = false
end)

You can remove FindFirstChild on Humanoid there too, it serves no much purpose.

The one problem is that any exploiter can remove the debounce, that's why i suggest you firing remote event to the server for it to heal the player and implement the debounce on the server, if you are just learning something, it is not necessary but in real games it can sometimes be bad.

1 comment

0

It works thank you so much for helping me!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.