Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

0

idk why it only put local strength to cash value in the script box the rest is apart of the script

0

Please format the question better, I can't tell what's what.

2 answers

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.

search youtube for Roblox studio debounce tutorial its really ez

This discussion is preserved as it was. New answers, comments, and votes are closed.