Hello developers! So I am trying to make a percentage BillboardGui that displays the life of a dummy, and I want it to turn red when the dummy gets damage. This works perfectly fine, but after the dummy dies the billboardGui stops turning red.
I think is because after the dummy dies, the script wants to color the old BillboardGui that dosen’t exist anymore(the one that the dead dummy had) and not the current one. Thats why I added :WaitForChild, but still nothing happens.
Here is the code:
local dummy = script.Parent
local humanoid = dummy.Humanoid
local percentage = 100
local currentHealth = humanoid.MaxHealth
humanoid.HealthChanged:Connect(function()
currentHealth = humanoid.Health
percentage = 100 * (currentHealth / humanoid.MaxHealth) +1
dummy:WaitForChild("Head").BillboardGui.TextLabel.Text = math.round(percentage).."%"
while dummy:GetAttribute("getsAttacked") == true do
dummy:WaitForChild("Head").BillboardGui.TextLabel.TextColor3 = Color3.new(1, 0, 0)
wait()
end
wait(.25)
dummy:WaitForChild("Head").BillboardGui.TextLabel.TextColor3 = Color3.new(1, 1, 1)
end)
Please tell me if I need to provide more details.