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

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

Asked by 3 years ago
Edited 3 years ago
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.

0
I see I'll start writing an answer VVTF_RU 18 — 3y

1 answer

Log in to vote
0
Answered by
VVTF_RU 18
3 years ago
Edited 3 years ago

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)
0
Hopefully this works :D VVTF_RU 18 — 3y
0
Oh I'm stupid its because you didn't trigger it VVTF_RU 18 — 3y
0
I edited it it should work now VVTF_RU 18 — 3y
0
there is a problem with the 'end's TIZEE_BaconHair 0 — 3y
View all comments (2 more)
0
18:21:37.159 Players.Tizee_YBA.Backpack.Gem.Debounce/Cooldown:19: Expected identifier when parsing expression, got ')' - Studio - Debounce/Cooldown:19 TIZEE_BaconHair 0 — 3y
0
That still wouldn't work because onTouched is nil. Make sure That it is referenced JesseSong 3916 — 3y
Ad

Answer this question