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

Changing the Color of Gui wont work why??

player = game.Players.LocalPlayer
char = player.Character or player.CharacterAdded:Wait()
Human = char:WaitForChild('Humanoid')
healthframe = script.Parent
Imagelabel = script.Parent.Parent.Parent.ImageLabel

Human.HealthChanged:Connect(function(Hp)
	healthframe.Size = UDim2.new(Hp/Human.MaxHealth,0,0,0)
	
end)

if Human.Health < 70 then 
	Imagelabel = script.Parent.Parent.Parent.ImageLabel
	Imagelabel.ImageColor3 = Color3.new(111,111,111)
	
end

2 answers

Color3.new is followed by 0-1,0-1,0-1. You are probably looking for Color3.fromRGB which is followed by 0-255,0-255,0-255.

if Human.Health < 70 then 
    Imagelabel = script.Parent.Parent.Parent.ImageLabel
    Imagelabel.ImageColor3 = Color3.fromRGB(111,111,111)

end

This is where an if else statement comes in handy.


Right now, if your health goes below 70, it will stay that colour forever, since you haven't set it back. You can easily set it back by using an if else statement:

if x == 5 then
	print("x is equal to five!")
else
	print("x is not equal to five")
end

I've also notice you used Color3.new. It only takes values ranging from 0 to 1. Consider using Color3.fromRGB or dividing by 255.

Plugging this into your code, you get something like this:

local player = game.Players.LocalPlayer
local char = player.Character or local player.CharacterAdded:Wait()
local Human = char:WaitForChild('Humanoid')
local healthframe = script.Parent
local Imagelabel = script.Parent.Parent.Parent.ImageLabel
local defaultColor = Imagelabel.ImageColor3


Human.HealthChanged:Connect(function(Hp)
	healthframe.Size = UDim2.new(Hp/Human.MaxHealth,0,0,0)
end)

if Human.Health < 70 then
	Imagelabel.ImageColor3 = Color3.fromRGB(111,111,111)
else
	Imagelabel.ImageColor3 = defaultColor
end

Hope I helped!

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