Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

2 comments

0

thank you!

0

@Link, you're welcome!

This discussion is preserved as it was. New answers, comments, and votes are closed.