if healthvalue >= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if healthvalue >= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if healthvalue >= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
end)
(Sorry if this post is sloppy, I’m still learning how to use this)
So what you got right here is changing your face to the third one every time your health changes and what the dude up said, you should put <= and it should work fine, but it’s not a good idea to do it on client
local currentzone = nil
wait()
local player = game.Players.LocalPlayer
local character = player.Character
local healthvalue = character.Humanoid.Health
character.Humanoid.HealthChanged:Connect(function()
print(“Changed”)
if healthvalue <= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if healthvalue <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if healthvalue <= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
end)
if healthvalue <= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if healthvalue <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if healthvalue <= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
You’re not changing healthvalue from it’s original value.
character.Humanoid.HealthChanged:Connect(function()
print(“Changed”)
healthvalue = character.Humanoid.Health --new line
if healthvalue <= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if healthvalue <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if healthvalue <= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
end)```
I can see what you did wrong, you gave the health a variable which doesn’t update called: healthvalue
so first when the player their health is 100 and the variable gets set to 100 and when the player loses health it still stays 100, change the script either to:
local currentzone = nil
wait()
local player = game.Players.LocalPlayer
local character = player.Character
local hum = character.Humanoid
hum.HealthChanged:Connect(function()
print(“Changed; Value: ” .. tosting(hum.Health))
if hum.Health <= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if hum.Health <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if hum.Health<= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
end)
or every time the players health changes you do (before the script and just after the function):
Were you damaging the player client-sided/server-sided (I don’t think this matters as it’s client sided)
What amount of health did it print out every time you got damaged.
or it might be because, the 0 health face gets overwritten by the 5 health face and that get’s overwritten by the 20 health face; then change the script to the following (check next comment);
local currentzone = nil
wait()
local player = game.Players.LocalPlayer
local character = player.Character
local hum = character.Humanoid
hum.HealthChanged:Connect(function()
print(“Changed; Value: ” .. tosting(hum.Health))
if hum.Health == 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
elseif hum.Health <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
elseif hum.Health <= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
else
-- Default texture
end
end)
if hum.Health <= 0 then -- Died
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://145854465'
end
if hum.Health <= 5 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://128158698'
end
if hum.Health<= 20 then
script.Parent.ViewPortPerson.Head.Face.Texture = 'rbxassetid://162810397'
end
end)
Right now I have an error
I changed my health in the server and also reset my character
nothing printed
Oh, we forgot 1 thing; the player didn’t load fully in yet, the gui only loads in with the camera, it doesn’t care about the character so:
local currentzone -- If you don't give it a value it will be nil, no need to set it to nil
local Plr = game.Players.LocalPlayer
local Char = Plr.Character or Plr.CharacterAdded:Wait
local Hum = Char.Humanoid
You can change the names of the variables to whatever.