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

How do I add a cooldown so people cant spam click?

Asked by 3 years ago
Edited 3 years ago

local Players = game:GetService("Players")

local function leaderbaordFunction(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local Strength = Instance.new("IntValue")
Strength.Name = "Strength"
Strength.Parent = leaderstats
Strength.Value = 0

local Cash = Instance.new("IntValue")
Cash.Parent = leaderstats
Cash.Name = "Cash"
Cash.Value = 0  

end

Players.PlayerAdded:Connect(leaderbaordFunction)

local r = game.ReplicatedStorage.Click

r.OnServerEvent:Connect(function(player) player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 end)

0
idk why it only put local strength to cash value in the script box the rest is apart of the script alyssacathe1 0 — 3y
0
Please format the question better, I can't tell what's what. radiant_Light203 1166 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Generally we use debounces to stop code from running excessively after being triggered.

It looks a little like this:

local debounce = false

button.MouseButton1Click:Connect(function()
    if debounce == true then return end

    debounce = true
    -- do something


    wait(5) -- cooldown time
    debounce = false
end)

Try modifying your code to fit something like this in there.

Ad
Log in to vote
-1
Answered by 3 years ago

search youtube for Roblox studio debounce tutorial its really ez

Answer this question