Problem with part health gui

  1. What do you want to achieve? Keep it simple and clear!
    A part health gui that show a part health

  2. What is the issue? Include screenshots / videos if possible!
    The gui doesn’t show the health correctly and I have no idea what I am doing with it cause I can’t script well

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Can’t find anything

local MaxHealth = 100
local Health = script.Parent.Parent.Parent.Parent.Value.Value

script.Parent.Parent.Parent.Parent.Value.Changed:Connect(function()
	local damage = script.Parent.Parent.Parent.Parent.Value.Value
	script.Parent.Size = UDim2.new((Health - damage) / MaxHealth, 0, 1, 0)
	Health = Health - damage
end)

Can you send images of the Ui & the explorer (where the ‘values’ are) You should also name the values ‘Damage’ and ‘Haelth’

I’m going to assume that this is a BillboardGui so I’ll write and script and explain it, just give me a moment.

Here is a health bar I made a while back. I don’t know if this will help but you can take a look inside the script to see what’s what.

This is inserted into “StarterCharacterScripts” assuming the UI is a BillboardGui named “HealthUI”

local rs = game:GetService('ReplicatedStorage')

local par = script.Parent
local gui = par:WaitForChild('HealthUI')
local hum = par:WaitForChild('Humanoid')

local function updateHealth()
	rs.UpdateHealth:FireServer(hum.Health)
end

hum:GetPropertyChangedSignal('Health'):Connect(updateHealth)

This is the server script

local rs = game:GetService('ReplicatedStorage')

local event = rs:WaitForChild('UpdateHealth')

local function updateUI(player,health)
	local ui = player.Character:WaitForChild('HealthUI')
	ui.Frame.Size = UDim2.new(health/100,0,1,0)
end

event.OnServerEvent:Connect(updateUI)

You’ll obviously need to secure your events however I feel as this is mostly self explanatory.

I’m sorry for not explaining more but the gui is a surface gui in a part and I am trying to make the part have a health so I can damage it

Screenshot (62)

I would prob use humanoid but I’m not good at that kind of stuff so know that it wont 100% work.

As I see. In this case, you’d want to use a change event and make the “X” size in the Udim2 value divide by 100, as seen in the previous script I sent, assuming the max health is 100.

So I make a humanoid inside the part instead of value?

Not necessarily however it’s completely up to you!