关于使用 nil 索引 health 的尝试

我正在为我的 humanoid/enemy 制作一个生命条,但它一直显示尝试使用 nil 索引 health 以下是代码:

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

原文链接 https://stackoverflow.com/questions/70722785

点赞