I’m making a health GUI split into 3 sections. It will not work correctly, however. When the character’s health is above 1 and below 100, it doesn’t display the correct decal layer. I haven’t tried anything from other sites yet, I’ve just been stuck here trying to figure out why it won’t work correctly.
This is the script I’m using:
print("Running")
wait(0.01)
P = script.Parent.Parent.Parent.Character.Humanoid
G = script.Parent
while true do
wait(.01)
if P.Health == 100 then
print("Health")
script.Parent.HPiiii.Visible = false
script.Parent.HPiii.Visible = true
script.Parent.HPii.Visible = false
script.Parent.HPi.Visible = false
script.Parent.HP.Visible = false
end
-- Full
if P.Health >= 66 and P.Health <= 99 then
print("Health")
script.Parent.HPiiii.Visible = false
G.HPiii.Visible = false
script.Parent.HPii.Visible = true
script.Parent.HPi.Visible = false
script.Parent.HP.Visible = false
end
-- 2/3 ^
if P.Health > 0 and P.Health <= 65 then
print("Health")
script.Parent.HPiiii.Visible = false
script.Parent.HPiii.Visible = false
script.Parent.HPii.Visible = false
script.Parent.HPi.Visible = true
script.Parent.HP.Visible = false
end
-- 1/3 ^
if P.Health <= 0 then
print("Health")
script.Parent.HPiiii.Visible = false
script.Parent.HPiii.Visible = false
script.Parent.HPii.Visible = false
script.Parent.HPi.Visible = false
script.Parent.HP.Visible = true
end
-- None
print("Still Working")
end
Each HP is for each section. (ex. “HPiiii” = 3/3 + 1 HP, “HPiii” = 3/3 HP, and so on.) The fourth decal is for a shielded HP, meaning you have an extra HP (kind of). I really don’t know why it won’t work; it might be because of the values I’ve put in. I’ll try to fix it in the meantime after I eat my lunch. Thanks for reating!
local player = game.Players.LocalPlayer
repeat task.wait() until player.Character
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local parentFrame = script.Parent
local hp = parentFrame:WaitForChild("HP")
local hpi = parentFrame:WaitForChild("HPi")
local hpii = parentFrame:WaitForChild("HPii")
local hpiii = parentFrame:WaitForChild("HPiii")
function healthChanged(health)
if health >= 100 then
hp.Visible = false
hpi.Visible = false
hpii.Visible = false
hpiii.Visible = true
elseif health >= 66 then
hp.Visible = false
hpi.Visible = false
hpii.Visible = true
hpiii.Visible = false
elseif health > 0 then
hp.Visible = false
hpi.Visible = true
hpii.Visible = false
hpiii.Visible = false
else
hp.Visible = true
hpi.Visible = false
hpii.Visible = false
hpiii.Visible = false
end
end
humanoid.HealthChanged:Connect(healthChanged)
Note that I did not include a HPiiii because it does not seem to be used in your code as its visibility is never set to true. If this is by accident, this might also explain why you suddenly skipped from 66 to 0 in your health incrementation.
Let me know if you have any issues or further questions.
Thank you! It’s going to be a project similar to SUPER CHECK POINT. I have the lives system ready as well (SUPER CHECK POINT is just an obby with 30 stages and normally 5 lives.)