i tried to make a script that reduces energy when you attack. I made it decreases if 30 and stops if the player has below 30 energy;but, when the energy goes below 30 it makes players not attack anymore, why?
tool = script.Parent PunchEvent = game.Workspace.Attacks["Rico's Attacks"].Punch replicatedstorage = game:GetService("ReplicatedStorage") staticball = replicatedstorage.RicoClass:findFirstChild("Lightning") cooldown = false tool.Selected:connect(function(mouse) mouse.Button1Down:connect(function() if not cooldown then cooldown = true local player = game.Players.LocalPlayer local Energy = player.PlayerGui.ScreenGui.TextButton.TextBox.EnergyValue game:WaitForChild(player) if Energy.Value >= 30 then --------------------------checks player's energy Energy.Value = Energy.Value - 30 -------------decreases player's energy local player = game.Players.LocalPlayer local Humanoid = player.Character.Humanoid --------------------------------------------------------------------------------- local Punch = Instance.new("Animation") Punch.AnimationId = "http://www.roblox.com/Asset?ID=644505212" local animTrack = Humanoid:LoadAnimation(Punch) animTrack:Play(0,2,2.5) --------------------------------------------------------------------------------- PunchEvent:FireServer(mouse.Hit) wait(0.4) cooldown = false end end end) end)