Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I change the image of an ImageLabel when a player's health goes down?

Asked by 3 years ago

How do I change the image of an ImageLabel when the player's health goes below a specific level? I've tried to look up many tutorials and tried my own script but none of them work. Can I have a bit of help?

For example, I have an image that is green, indicating the player's health is at the max. But when it goes below a specific level, the image changes. However, there are two more specific places of health the player reaches to change the image again.

Can someone help me? (Sorry if it doesn't make any sense)

This is a script I found from a tutorial but it doesn't work.

repeat wait() until game:GetService("Players").LocalPlayer
local Character = workspace:FindFirstChild(game.Players.LocalPlayer.Name)

while wait() do
    if Character:FindFirstChild("Humanoid") then    
        if Character.Humanoid.Health.Value >= 75 then
            script.Parent.ScreenGui.ImageLabel.Image = "rbxassetid://6105945560"
        end
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago

Hello! I think one of the problems is that you have >= 75 and it should be <= 75. I could be wrong, I'm not sure, but when I changed a few things it worked, so I hope this works for you!

repeat wait() until game:GetService("Players").LocalPlayer
local Character = workspace:FindFirstChild(game.Players.LocalPlayer.Name)

while wait() do
    if Character:FindFirstChild("Humanoid") then    
        if Character.Humanoid.Health <= 75
        then
             script.Parent.ScreenGui.ImageLabel.Image = "rbxassetid://6105945560"

        end
    end
end

I put this into a local script and it worked. Good luck and I hope it works!

0
thank you! LinkZelda_Sage 16 — 3y
0
@Link, you're welcome! PadmeOragana 78 — 3y
Ad

Answer this question