I've been trying to make a Click for Cash button in Roblox, only to find out that the cooldown/debounce can also happen to other players. I've tried switching the Scripts to Local Scripts, but it does not work (I'm a beginner at coding) This is my code right now (Getting Money Script):
local cooldown = false local COOLDOWN_TIME = 10 local Players = game:GetService("Players") local plr = Players.LocalPlayer local clickDetector = script.Parent.ClickDetector local timeRemaining = 10 clickDetector.MouseClick:Connect(function(player) if cooldown == false then cooldown = true player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,200) * math.random(1,500) - math.random(1,5000) repeat print(timeRemaining) wait(1) timeRemaining = timeRemaining - 1 until timeRemaining == 0 if timeRemaining == 0 then cooldown = false timeRemaining = 10 else return end elseif cooldown == true then return end end)
(Cooldown Appearance Script):
local cooldown = false local CD = script.Parent.ClickDetector CD.MouseClick:Connect(function() if cooldown == false then cooldown = true for count = 10, 0, -1 do script.Parent.Parent.ClickGiveMoneyBase.BillboardGui.TextLabel.Text = count wait(1) end script.Parent.Parent.ClickGiveMoneyBase.BillboardGui.TextLabel.Text = "Click this Button to Give you CASH!" cooldown = false elseif cooldown == true then return end end)
More clearance to my problem: When a player clicks and cooldown happens, it not only happens on the player that clicked the part, but also on other players in the server.
Move the localscript to StarterPlayer > StarterCharacterScripts > here, then Press workspace and on properties enable FilteringEnabled, then change
local clickDetector = script.Parent.ClickDetector
to
local clickDetector = workspace.Button.ClickDetector --Whatever the path is
because the parent wont be the button more. Also when adding the money of the button make it via Remote functions and to prevent exploiters add also a cooldown on the Remote function