I want to make a npc hover health bar but the problem is that it doesn’t work. ( the problem by my knowledge is the local script can’t find the humanoid)
local humanoid = script.Parent.Parent.Parent.Parent:WaitForChild("Humanoid")
local healthNUM = script.Parent.Parent.healthNUM
humanoid.HealthChanged:Connect(function(Damage)
script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0,1,0)
end)
local function Number()
healthNUM.Text = humanoid.Health.."/"..humanoid.MaxHealth
end
Number()
humanoid.HealthChanged:Connect(Number)
some of my script that require Humanoid doesn’t work cause of script cant find Humanoid
Put a screenshot of your hierarchy
If it is a local script you can just do
local pl = game.Players.LocalPlayer
local char = pl.Character
local hum = char:FindFirstChild(“Humanoid”)
Also post here the output error
i think you also need to do
healthNum.Text = ToString(humanoid.Health) … “/” … ToString(Humanoid.MaxHealth)
lht2007
(OnlyCat)
March 22, 2022, 10:35am
#6
The humanoid has the same parent as the billboard?
lht2007
(OnlyCat)
March 22, 2022, 10:36am
#7
I think u just forgot to add one more .parent before finding the humanoid
The whole hierarchy, i want to see what is the billboardgui parented to
Also instead of
humanoid.HealthChanged:Connect(Number)
try
humanoid.HealthChanged:Connect(Number())
And this
local healthNUM = script.Parent.Parent.healthNUM
is not an error but why not just do
local healthNUM = script.Parent
:DDD
lht2007
(OnlyCat)
March 22, 2022, 10:40am
#12
U forgot to add one more parent
lht2007
(OnlyCat)
March 22, 2022, 10:41am
#13
script.Parent.Parent.Parent.Parent.Parent:WaitForChild(“Humanoid”) should fix it
lht2007
(OnlyCat)
March 22, 2022, 10:42am
#14
U should really check u script before u ask, especially when it is a index not found
script.Parent.Parent.Parent.Parent in your case is Head, which doesnt have a humanoid
As mentioned above, you need to add one more parent, which will be the enemy character, which Does have humanoid
is this right? i have change it
local humanoid = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Humanoid")
local healthNUM = script.Parent
local pl = game.Players.LocalPlayer
local char = pl.Character
local hum = char.Parent:FindFirstChild("Humanoid")
humanoid.HealthChanged:Connect(function(Damage)
script.Parent.Size = UDim2.new(Damage / humanoid.MaxHealth, 0,1,0)
end)
local function Number()
healthNUM.Text = tostring (humanoid.Health) .."/".. tostring (humanoid.MaxHealth)
end
Number()
humanoid.HealthChanged:Connect(Number())
It should be, have you tried it?
the healthbar gui didn’t change when i decrease the health of the npc
oh no xD, wait ill fix it for ya
look the whole point of this section
local pl = game.Players.LocalPlayer
local char = pl.Character
local hum = char.Parent:FindFirstChild("Humanoid")
was to find humanoid another way instead of
local humanoid = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Humanoid")