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

Tool Currency Giver Cooldown? [closed]

Asked by 5 years ago

This question already has an answer here:

How Do I add an cooldown in this tool??? (help please)

Hello, I Really Need Help In This And I'm A Beginner Is Coding So Could You Please Help Me With This Script??

01local db = false
02local tool = script.Parent
03repeat wait() until tool.Parent.Parent:IsA("Player")
04local plr = tool.Parent.Parent
05local character = plr.Character
06 
07tool.Activated:Connect(function()
08    if not db then
09        plr.leaderstats.Power.Value = plr.leaderstats.Power.Value + 1
10        db = false
11    end
12end)

Marked as Duplicate by User#6546

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
5 years ago

Your debounce isn't set up correctly. You set debounce to false even though it is already false and you have no cooldown.

01local db = false
02local tool = script.Parent
03repeat wait() until tool.Parent.Parent:IsA("Player")
04local plr = tool.Parent.Parent
05local character = plr.Character
06 
07tool.Activated:Connect(function()
08    if not db then
09        db = true
10        plr.leaderstats.Power.Value = plr.leaderstats.Power.Value + 1
11        wait(1) -- this is the cooldown, edit 1 to whatever number to make it longer or shorter
12        db = false
13    end
14end)

You can use roblox's sample on debounce if you need more help with it: https://developer.roblox.com/en-us/articles/Debounce

Ad