I’ve been trying to make a heart icon that changes images depending on the player’s health. Basically, being more broken and broken.
Here’s my script:
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid")
local image = script.Parent
if newvalue <= 100 then
image.Image = "https://www.roblox.com/library/7917732450/100hpicon"
if newvalue <= 75 then
image.Image = "https://www.roblox.com/library/7917733668/75hp"
if newvalue <= 50 then
image.Image = "https://www.roblox.com/library/7917734933/50hp"
if newvalue <= 35 then
image.Image = "https://www.roblox.com/library/7917736453/35hpicon"
if newvalue <= 20 then
image.Image = "https://www.roblox.com/library/7917737527/20hpicon"
No matter what I do, the image won’t change when the health is 75, or 50, etc. I’m really clueless as to what I did wrong, so any help would be appreciated. (Yes, the local script is inside the image).
FOR SOLUTION: Make sure to add a > at and newvalue = (>=)
To change the image, the normal URL won’t work. Instead, you need to replace all
image.Image = "https://www.roblox.com/library/id/name" (Normal URLS)
image.Image = "rbxassetid://7917737527" (rbxassetid://)
I Will try it, I usually forget to use that URL lol
Still doesn’t work, thank you for letting me know about the URL error though!
perhaps try to use
elseif instead of creating several different
if statements then. also, try printing the
newvalue variable just to make sure.
example would be
if v1 == v2 then
elseif v3 == v4 then
Edit: Forgot to ask, did you get any error? Because there is a
) missing on the last
Did your player take damage and it won’t update or are you changing the health through the properties window?
You can use a white image and change it’s
ImageColor3 property instead.
Ah no, I just forgot to select that when copying the script to paste it here, my bad.
Player is taking damage and won’t update.
Dunno if you can do that with different images, they’re all IDs for different images
Oh, I though you are making a health bar that changes it’s color based on health.
No worries, already done that!
(The health bar will change color depending on health, it’s the blue-ish outline around the circle)
The elseif in this case would jsut make the first true and then it won’t continue since it is 100 or less
oh yeah, didn’t notice that. in that case you would have to add an
and statement to make sure the HP are in the specific area.
if newvalue <= 100 and newvalue > 75 then
-- do stuff
Still doesn’t seem to work… Maybe it’s the humanoid.HealthChanged? I probably used it in a wrong way and I’m not realizing it.
I don’t see anything wrong with it right now. Try printing
newvalue when the function starts and check if and what it prints, perhaps that helps.
I get this, any idea on what it means?
The humanoid is nil. Perhaps it’s not loaded in when it’s needed, so replace
:WaitForChild() in Line 3.
It does something, however the image just disappears, doesn’t appear again even if I healed to max HP
Edit: It re-appears when you respawn