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

How do I change the color of an ImageColor3 property?

This is a server script. It's supposed to change the health bar gui of an enemy depending on it's humanoid health but the color of the bar won't change

local char = script.Parent.Parent.Parent.Parent.Humanoid

char.Changed:Connect(function()
	local redzone = char.MaxHealth/4
	if char.Health <= redzone then -- if in redzone then chage to red
		script.Parent.Health.ImageColor3 = Color3.new(255,0,0) -- Gives me an error, "ImageColor3 is not a valid member of Script"
	end
	if char.Health > redzone then -- if not in redzone then stay or change to green
		script.Parent.Health.ImageColor3 = Color3.new(41, 255, 119)
	end
	script.Parent.Health.Size = UDim2.new(char.Health/char.MaxHealth,0,0,15)
end)

1 comment

0

nvm i fixed it, i changed Color3.new() to Color3.fromRGB. I also put the script inside of the health gui

2 answers

✓ Accepted answer

ANSWER: Your script.Parent.Health does not have a property that is ImageColor3 and it appears instead to be a script that you are referencing. (That is the translation of your error) you need to look at your heirarchy and make sure that script.Parent.Health is referring to the ImageLabel / ImageButton that you're trying to change the ImageColor3 of.

Note: You also need to be using Color3.fromRGB() instead of Color3.new() line 6,9

Your code with the fix:

local char = script.Parent.Parent.Parent.Parent.Humanoid

char.Changed:Connect(function()
	local redzone = char.MaxHealth/4
	if char.Health <= redzone then
		script.Parent.Health.ImageColor3 = Color3.fromRGB(255,0,0)
	end
	if char.Health > redzone then
		script.Parent.Health.ImageColor3 = Color3.fromRGB(41, 255, 119)
	end
	script.Parent.Health.Size = UDim2.new(char.Health/char.MaxHealth,0,0,15)
end)

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