Try this instead
local player = game.Players.LocalPlayer
local frame = script.Parent
local container = frame.Parent
container.BackgroundColor3 = Color3.new(0, 0, 0)
local function onHealthChanged()
local human = player.Character.Humanoid
local percent = human.Health / human.MaxHealth
frame.Size = UDim2.new(percent, 0, 1, 0)
if percent < .1 then
frame.BackgroundColor3 = Color3.new(1, 0, 0)
elseif percent < .4 then
frame.BackgroundColor3 = Color3.new(1, 1, 0)
else
frame.BackgroundColor3 = Color3.new(0, 1, 0)
end
end
local function onCharacterAdded(character)
local human = character:WaitForChild("Humanoid")
human.HealthChanged:Connect(onHealthChanged)
onHealthChanged()
end
player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
onCharacterAdded(player.Character)
end
This is from the roblox wiki
instead
1 comment
Change the character for the NPC