Let’s get straight to the problem, I made a bar system that when the key Z is pressed the bar will go down and when it has an specific size it will have like a re-fill effect, soo It would be easily exploited and cheated and it was kind of buggy and I tried to make a cooldown for it, it works when I press Z but the bar doesn’t go back up how it used to, here is the code and its a localscript.
--// CONFIGURATIONS \\--
local x = game.ReplicatedStorage.Classes.TestClass.Cooldown.Value
local xConsume = 4
local xReload = 6
local Cooldown = false
debounce = true
--// VARIABLES \\--
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local RunService = game:GetService("RunService")
local MainBar = script.Parent.MainBar
local Bar = MainBar.Bar
local Text = MainBar.Text
--// MAIN CODE \\--
if debounce then
UserInputService.InputBegan:Connect(function(Input)
if not Cooldown then
if Input.KeyCode == Enum.KeyCode.Z then
MainBar.Bar:TweenSize(UDim2.new(0, 0,0, 53), "In", "Quad", x - 12)
wait(xConsume)
Cooldown = true
debounce = false
end
end
end)
end
if debounce == false then
RunService.Heartbeat:Connect(function()
if Cooldown then
if MainBar.Bar.Size == UDim2.new(0, 0,0, 53) then
wait(0.6)
MainBar.Bar:TweenSize(UDim2.new(0, 205,0, 53), "In", "Quad", x)
wait(xReload)
Cooldown = false
debounce = true
end
end
end)
end