#Help with Roblox Health Bar Script

1 messages · Page 1 of 1 (latest)

pale heron
#

I'm working on a Roblox script to create a health bar UI for the local player. The health bar (a Frame) should resize based on the player's health, and a TextLabel should display the health percentage.

#

Here's my current GUI hierarchy in the Explorer:

#

My script

-- Variables

local Player = game.Players.LocalPlayer
local Chracter = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Chracter:WaitForChild("Humanoid")

local Healthbar = script.Parent    

local function UpdateHeath()
    local size = math.clamp(Humanoid.Health / Humanoid.MaxHealth, 0, 1)
    Healthbar.Size = UDim2.new(size, 0, 1, 0)
    script.Parent.Parent.Parent.Percentage.Text = tostring(math.floor(size * 100 )).. "%"
end

UpdateHeath()
Humanoid:GetPropertyChangedSignal("Health"):Connect(UpdateHeath)
Humanoid:GetPropertyChangedSignal("MaxHealth"):Connect(UpdateHeath)
#

the current problem I'm facing is:

I've tried correcting typos, changing the path to the Percentage label

Could someone please help me understand why the script can't find the "Percentage" TextLabel and how I can fix the path in the script?

Thank you for your help!

spare bane
#

idk