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

How to make a cool Down on click for Points? (read desc)

Hi so how what would I add to this script to make it where you cant spam click like a cool down? I tired wait command but it just adds up all the click after the wait is over? Here's the script-

local player = game.Players.LocalPlayer

script.parent.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		player.leaderstats.points.Value = player.leaderstats.points.Value + 1
	end)
end)

This would help and as you can see its not that big of a script just a simple one that goes into a tool.

1 answer

✓ Accepted answer

You can use a debounce. This is a form of Boolean manipulation which conditions our code to stop in it's tracks when we tell it to, and continue when we do the opposite.

local Player = game:GetService("Players").LocalPlayer

local CanUse = true

local Tool = script.Parent

Tool.Equipped:Connect(function(Cursor)
	local Leaderstats = Player:WaitForChild("Leaderstats")
	local Points = Leaderstats:FindFIrstChild("Points")
	Cursor.Button1Down:Connect(function()
		if (Points) then
			if not (CanUse) then return end; CanUse = false
			Points.Value = (Points.Value + 1)
			wait(1)
			CanUse = true
		end
	end)
end)

1 comment

0

Thank you Feahren Check out my game in free week rn!

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