Trouble with viewportframe profile face

I’m having trouble with changing the face of a viewport frame model, I want it to display faces if you are at a certain amount of health!

Problem: “It’s not updating the faces”

Here’s what I got so far:

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)

(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

If you want to 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)

Do this:

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

No errors were printed, its not an error

Is this on client or server sided?

The script is in the Player’s gui, “Client Sided”

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):

healthvalue = character.Humanoid.Health
1 Like

It’s still showing the default face
image

Its suppose to look like this: image

  1. What’s the script right now?
  2. Any errors,
  3. Were you damaging the player client-sided/server-sided (I don’t think this matters as it’s client sided)
  4. What amount of health did it print out every time you got damaged.
  5. 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)

The script is:

the 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)

Right now I have an errorimage
I changed my health in the server and also reset my character
nothing printed

(before change in code)

I updated it and its still sayingimage

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.

Thank you! The problem was a small type @royaltoe pointed it out in my DM’s! Thank both of you! :slight_smile:

2 Likes