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

how would i use debounce in this situation?

how would i use debounce in this situtation? ive looked on the wiki and it doesnt make much sense to me. Also how would i be able to make it so if someone clicked they would have to wait a few seconds before they can click again? i dont think im doing it right

local mouse = game.Players.LocalPlayer:GetMouse()
local clicks = 0
	wait(5)
	mouse.Button1Down:connect(function()
			clicks = clicks + 1
	if clicks == 3 then	
		for i = 1,1 do
local Leaderstats = game.Players.LocalPlayer.leaderstats:findFirstChild("Strength")
			if Leaderstats ~= nil then
				for i = 1,1 do
				Leaderstats.Value = Leaderstats.Value + 1
				wait(5)
				clicks = 0
	
						end
					end
				end
			end
		end
end)

1 answer

✓ Accepted answer

pss, your script looks messy cause your not using indents right ;p

Ok so to make a debounce we are going to create a bool variable outside this mess, then with they click check if it is true, if so make it false, at the end of the click event we wait a few seconds then make it true again.

local mouse = game.Players.LocalPlayer:GetMouse()
local clicks = 0
local d = true 

wait(5)

mouse.Button1Down:connect(function()
	if d==true then d=false --debounce
		clicks = clicks + 1
		if clicks == 3 then 
			for i = 1,1 do
				local Leaderstats = game.Players.LocalPlayer.leaderstats:findFirstChild("Strength")
				if Leaderstats ~= nil then
					for i = 1,1 do
						Leaderstats.Value = Leaderstats.Value + 1
						clicks = 0
					end
				end
			end
		end
	end
	wait(5) --debounce wait
	d=true --change back
end)

2 comments

0

You could just do "if d then d = false". Also, "findFirstChild" is deprecated, use "FindFirstChild".

0

@hiimgoodpack tis a habit of mine

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