Hey soo I made a script that prevents users from spam clicking but uhh when they hold the click it gives them the currency x2 faster than anticipated and I don’t really know how to fix it, here is the code of the tool:
-- CONFIGS
local Cooldown = 0.1
local IsHolding = false
local SwordValue = false
local CanUse = false
local debounce = true
-- SERVICES
local RepStorage = game:GetService("ReplicatedScriptService")
local ScriptService = game:GetService("ServerScriptService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
-- VARIABLES
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
--local Event = game.ReplicatedStorage.Events.RemoteEvents.ToolMain
local Sound = game.ReplicatedStorage.Assets.SwingSound
-- MAIN CODE
script.Parent.Activated:Connect(function()
if debounce == true then
debounce = false
IsHolding = true
CanUse = true
while IsHolding == true do
if not CanUse then break end
if SwordValue == false then
SwordValue = true
Sound:Play()
wait(Cooldown + 0.05)
if not CanUse then break end
Player.leaderstats.Swings.Value = Player.leaderstats.Swings.Value + 1
SwordValue = false
end
end
-- PREVENTING SPAM CLICKING
repeat wait(0.2) until not SwordValue
debounce = true
end
end)
script.Parent.Deactivated:Connect(function()
IsHolding = false
end)