Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

0
i need an answer helpp proudCdthekitten 22 — 3y

2 answers

Log in to vote
0
Answered by
Sparks 534 Moderation Voter
3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago

help me

Answer this question