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)

2 comments
Try explaining this question a little more. I'm a bit confused when trying to help, it's not attacking when it's below 30 because the script says if energy.Value >= 30 so if it's 29 this obviously wont run, however, I don't think this is what you are asking.
I am confused. Please try explaining a little more. It sounds like you have this script that stops players from attacking when their energy is below 30, but then it seems the players can't attack when their energy is below 30?