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

How do I make leader stats go up if a tool is clicked, with a delay?

local Debounce = false
local tool = script.Parent
local player = script.Parent.Parent.Parent

function onTouched(hit)
	if not Debounce then
	tool.Activated:Connect(function()
	player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 1
end)

Debounce = true
wait(.2)     
Debounce = false
end
end

script.Parent.Handle.Touched:connect(onTouched)

Here is the script. i dont know why it dosent work im a beginner. please help.

1 comment

0

I see I'll start writing an answer

1 answer

Ok so pretty much you did the debounce wrong you should do it inside of the first function, like this.

	local Debounce = false
	
	local tool = script.Parent
	
	local player = script.Parent.Parent.Parent
	
		    tool.Activated:Connect(function()
		
			if not Debounce then
	
			Debounce = true		   
	
		 	player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 1
	
			wait(2)     
	
			Debounce = false
	
		end)
	
	end

end


script.Parent.Handle.Touched:connect(onTouched)

6 comments

0

Hopefully this works :D

0

Oh I'm stupid its because you didn't trigger it

0

I edited it it should work now

0

there is a problem with the 'end's

0

18:21:37.159 Players.Tizee_YBA.Backpack.Gem.Debounce/Cooldown:19: Expected identifier when parsing expression, got ')' - Studio - Debounce/Cooldown:19

0

That still wouldn't work because onTouched is nil. Make sure That it is referenced

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