Roblox Health/Energy/Experience Bar script

So I’m currently creating a game which you can engage in combat with bosses/players/npcs etc…
I created a gui which would record the Health/Experience/Energy image
As shown. The Experience bar is unfinished and the Health bar works. Whilst I was testing the Energy bar I realised it wouldn’t change unless you reset. Their are no errors in the output. This is the scripting within it

local Players = game:GetService(“Players”)

local Workspace = game:GetService(“Workspace”)

local Player = Players.LocalPlayer

local Humanoid = Player.leaderstats2

local UI = Player.PlayerGui:WaitForChild(“Statistics”)

local Elements = UI:WaitForChild(“HUDPlayer”)

local MaxEnergy = Humanoid.Level.Value * 100

local Energy = Humanoid:WaitForChild(“Energy”).Value

local Stats = Elements

local Health = Stats:WaitForChild(“Energy”)

local MaxHealth = Stats:WaitForChild(“MaxEnergy”)

Health.Size = UDim2.new(0, MaxHealth.Size.X.Offset / MaxEnergy * Energy, 0, 25)

Humanoid.Energy.Changed:Connect(function()

Health.Size = UDim2.new(0, MaxHealth.Size.X.Offset / MaxEnergy * Energy, 0, 25)

end)

EDIT: The script is a local script.

2 Likes

You are changing health instead of energy
Humanoid.Energy.Changed:Connect(function()
Health.Size = UDim2.new(0, MaxHealth.Size.X.Offset / MaxEnergy * Energy, 0, 25)
end)

1 Like

Maybe try using enum.humanoidstate to change it the energy bar. This may be wrong, I’m not the best with guis.

1 Like

I believe the energy is a value he created inside the humanoid:

1 Like

Health is a variable. Thus your solution won’t work.