Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

NPC BillboardGui Health bar won't move when health gets changed?

Asked by 6 years ago

When I change the health of the humanoid the healthbar dosen't move at all.

local Humanoid = script.Parent.Parent.Parent.Parent.Parent.Humanoid

Humanoid.Changed:Connect(function()
   script.Parent.Size = UDim2.new((Humanoid.Health/Humanoid.MaxHealth), 0, 1, 0)
   wait()
end)
0
ServerScript inside a billboardgui insides 3 frames Bloxulen 88 — 6y

2 answers

Log in to vote
1
Answered by
Vexture 179
6 years ago
Edited 6 years ago

Everything here was done right. When you were changing the health value, you were changing it from the client and you have filtering enabled. If you go to Test and change it to server side and change the health, it works. :)

1
thanks mr vex Bloxulen 88 — 6y
1
yw mr blox Vexture 179 — 6y
Ad
Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

Change the script.Parent.Parent.Parent.Parent.Parent.Humanoid for script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Humanoid") and you can use :FindFirstChild() for detect if finded the Humanoid

Here is your fixed script:

wait()

if script.Parent.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid") then
    local Humanoid = script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Humanoid")
    Humanoid.Changed:Connect(function()
       script.Parent.Size = UDim2.new((Humanoid.Health/Humanoid.MaxHealth), 0, 1, 0)
       wait()
    end)
else
    print("Can not found Humanoid!")
end

Remember, change the value with Server. for this use Server Scripts or RemoteEvents...

Hope it helped :D

Wiki pages:

FindFirstChild

WaitForChild

Errors? tell-me on comments.

0
not working either, no errors Bloxulen 88 — 6y

Answer this question