Mob Health GUI delayed?

I want to make a custom health and name gui for the mobs in my game.

This the script that I use:

local gui = script.Parent
local text = gui.Frame.TextLabel.Text
local health = gui.Parent:WaitForChild("Humanoid").Health
local maxHealth = gui.Parent:WaitForChild("Humanoid").MaxHealth
local healthGui = gui.CurrentHealth

local percent = health / maxHealth

while true do
	healthGui.Size = UDim2.new(percent, 0, 1, 0)
	wait()
end


image

Whenever it runs, the BillBoardGui seems to lag behind the mobs, and the health bar does not update when damaged.

The GUI’s lagging behind I am unsure of, are they adornee’d to the mobs? As for the health bar not updating; try moving the percent variable inside the loop, that way it gets the current health constantly rather than just once when the game initializes.

1 Like

I moved percent inside the loop, so not the health bar does update correctly.

EDIT:

I changed the adornee from the mob group to its HumanoidRootPart, which fixed the lag issue

Try this at least

local gui = script.Parent
local text = gui.Frame.TextLabel.Text
local health = gui.Parent:WaitForChild("Humanoid").Health
local maxHealth = gui.Parent:WaitForChild("Humanoid").MaxHealth
local healthGui = gui.CurrentHealth

gui.parent:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
healthGui.Size = UDim2.new(health / maxHealth, 0, 1, 0)
end

Real sorry you gotta do the MaxHealth one on your own because mobile copy paste was being terrible and uses “” and stuff so it converted colons and quotes to % things.
Only thing I can think of for your other issue is improper parenting

This runs better than while true do loop and is better practice.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.