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

How to make a cool Down on click for Points? (read desc)

Asked by 4 years ago

Hi so how what would I add to this script to make it where you cant spam click like a cool down? I tired wait command but it just adds up all the click after the wait is over? Here's the script-

local player = game.Players.LocalPlayer

script.parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        player.leaderstats.points.Value = player.leaderstats.points.Value + 1
    end)
end)

This would help and as you can see its not that big of a script just a simple one that goes into a tool.

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use a debounce. This is a form of Boolean manipulation which conditions our code to stop in it's tracks when we tell it to, and continue when we do the opposite.

local Player = game:GetService("Players").LocalPlayer

local CanUse = true

local Tool = script.Parent

Tool.Equipped:Connect(function(Cursor)
    local Leaderstats = Player:WaitForChild("Leaderstats")
    local Points = Leaderstats:FindFIrstChild("Points")
    Cursor.Button1Down:Connect(function()
        if (Points) then
            if not (CanUse) then return end; CanUse = false
            Points.Value = (Points.Value + 1)
            wait(1)
            CanUse = true
        end
    end)
end)
0
Thank you Feahren Check out my game in free week rn! JuzeyPlayz -83 — 4y
Ad

Answer this question