How to change imageLabel colors locally

What do I want to achieve?
I want to understand how to change an imageLabel’s ImageColor3 locally.

What is the issue?
my script is not working that involves changing an imageLabel’s ImageColor3 to red as a damage indicator.

What solutions have I tried so far?
I tried looking on Youtube, other script help pages related to ImageColor3, and the Devforum + The ImageColor3 API Reference page.

In StarterPlayerScripts, I have a localScript in that localScript:

local player = game.Players.LocalPlayer.Character

if player.Humanoid <= 99 then
	
game.StarterGui.BetterHealthBar.Frame.ImageLabel.ImageColor3 = Color3.fromRGB(255, 55, 80)
	
else
	
game.StarterGui.BetterHealthBar.Frame.ImageLabel.ImageColor3 = Color3.fromRGB(255, 255, 255)
	
end

Basically players will be able to attack each-other, and I want there to be a little pixel icon that will turn red when the player is damaged, and once the health is at 100, it will not be red anymore.

BetterHealthBar = ScreenGui
Frame = Frame
ImageLabel = ImageLabel (Which I am trying to change the color of.)

Hey there, your script won’t work because of a couple reasons:

  1. You’re referencing StarterGui. StarterGui isn’t actually where the players UI is located. Instead, it is located in PlayerGui. StarterGui is really just a “container”. Every time a client connects, anything inside of StarterGui is replicated to PlayerGui.

  2. You’ll have to reference the Humanoids Health property, rather than the humanoid itself.

  3. It looks like you’re only detecting the change once. The script will only check if the players Humanoid health is bigger than or equal to 99 a single time. Instead, try the following script. It should work out.

local player = game.Players.LocalPlayer
local playerGui = player.PlayerGui
local character = player.Character

local function onHealthChange()
	if character.Humanoid.Health >= 99 then
		playerGui.BetterHealthBar.Frame.ImageLabel.ImageColor3 = Color3.fromRGB(255, 55, 80)
	else
		playerGui.BetterHealthBar.Frame.ImageLabel.ImageColor3 = Color3.fromRGB(255, 255, 255)
	end
end

character.Humanoid:GetPropertyChangedSignal("Health"):Connect(onHealthChange)

Also might be better to put this in StarterCharacterScripts honestly. It’d be easier to declare the character as script.Parent.

2 Likes