2 years ago

#54843

test-img

Denhemmelige2

attempt to index nil with health

i am making a health bar to my humanoid/enemy but it keeps saying attempt to index nil with health here is the code:

local Humanoid = script.Parent.Parent.Parent.Parent.Parent:FindFirstChild("Humanoid")
while true do
    wait(0.1)
    if Humanoid.Health <= 100 then
        script.Parent.Healthbar.BackgroundColor3 = Color3.fromRGB(17, 255, 0)
    end 
    if Humanoid.Health <= 50 then
        script.Parent.Healthbar.BackgroundColor3 = Color3.fromRGB(255, 255, 0)
    end
        script.Parent.Healthbar.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
    end
    script.Parent.HealthNum.Text = math.floor(Humanoid.Health) .. " / " .. math.floor(Humanoid.MaxHealth)
    local pie = (Humanoid.Health / Humanoid.MaxHealth)
    script.Parent.Healthbar.Size = UDim2.new(pie, 0, 1, 0)
end

lua

roblox

0 Answers

Your Answer

Accepted video resources