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

How can i make a timed click to +1 leaderstats?

so I wanted to make a click to add 1 to my leaderstats that worked then somewhere else i needed a timer I tried adding a timer

script.Parent.Activated:Connect(function() local char = script.Parent.Parent local plr = game.Players:GetPlayerFromCharacter(char) local leaderstats = plr:FindFirstChild("leaderstats") if leaderstats then local coins = leaderstats:FindFirstChild("Cash") local boost = plr:FindFirstChild("CoinBoost") if coins and boost then coins.Value = coins.Value + 1 + boost.Value end end end)

thats my click to add 1 to leaderstats i need a timer so when you click you have to wait however much time you put to be able to click again to earn money

1 comment

0

i need an answer helpp

2 answers

✓ Accepted answer

If this is a tool in a local script, you'll have to use a RemoteEvent to tell the server to update the leaderstat as changes you make on the client will not replicate to others. Nevertheless, here is what you requested. Assuming your code is on the server, you will need to add a debounce for each player to determine when they can click again. This can be done with a BoolValue.


script.Parent.Activated:Connect(function() 
	local char = script.Parent.Parent 
	local plr = game.Players:GetPlayerFromCharacter(char)

	local debounce = char.Debounce or Instance.new("BoolValue", char)
	debounce.Name = "Debounce"

	local leaderstats = plr:FindFirstChild("leaderstats")
	if leaderstats and debounce.Value == false then 
		debounce.Value = true
		local coins = leaderstats:FindFirstChild("Cash")
		local boost = plr:FindFirstChild("CoinBoost") 
		if coins and boost then 
			coins.Value = coins.Value + 1 + boost.Value 
		end 
		wait(1) --Change to cooldown
		debounce.Value = false
	end 
end)

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