Kryptalys
(Kryptalys)
1
-
What do you want to achieve?
I would like to have the bar change color depending on its size.
-
What is the issue?
The bar isn’t changing color at all.
-
What solutions have you tried so far?
I have tried looking and tried multiple ways to fix but nothing is working.
It shows an error in the output saying trying to compare a Udim2 < Udim2.
Below is the code.
Location: child of the frame aka bar in a localscript
local bar = script.Parent;
if bar.Size > UDim2.new(0.75, 0, 1, 0) then
bar.BackgroundColor3 = Color3.new(0, 0.666667, 0);
elseif bar.Size > UDim2.new(0.50, 0, 1, 0) and bar.Size < UDim2.new(0.75, 0, 1, 0) then
bar.BackgroundColor3 = Color3.new(0.784314, 1, 0.192157);
elseif bar.Size > UDim2.new(0.25, 0, 1, 0) and bar.Size < UDim2.new(0.50, 0, 1, 0) then
bar.BackgroundColor3 = Color3.new(1, 0.756863, 0.188235);
elseif bar.Size > UDim2.new(0, 0, 1, 0) and bar.Size < UDim2.new(0.25, 0, 1, 0) then
bar.BackgroundColor3 = Color3.new(0.666667, 0, 0);
end
Any and all help would be nice and thank you in advanced.
1 Like
Try Color3.fromRGB()
[character] [character]
kalabgs
(FartFella)
3
local bar = script.Parent;
elseif bar.Size.X.Scale > 0.75 then
bar.BackgroundColor3 = Color3.new(0, 0.666667, 0);
elseif bar.Size.X.Scale > 0.5 then
bar.BackgroundColor3 = Color3.new(0.784314, 1, 0.192157);
elseif bar.Size.X.Scale > 0.25 then
bar.BackgroundColor3 = Color3.new(1, 0.756863, 0.188235);
elseif bar.Size.X.Scale > 0 then
bar.BackgroundColor3 = Color3.new(0.666667, 0, 0);
end
Kryptalys
(Kryptalys)
4
I tried both of the ideas the 2nd post got rid of the error in the output but with this new code the bar still isn’t changing color.
code updated:
local bar = script.Parent;
if bar.Size.X.Scale > 0.75 then
bar.BackgroundColor3 = Color3.fromRGB(0, 170, 0);
elseif bar.Size.X.Scale > 0.5 and bar.Size.X.Scale < 0.75 then
bar.BackgroundColor3 = Color3.fromRGB(218, 227, 43);
elseif bar.Size.X.Scale > 0.25 and bar.Size.X.Scale < 0.5 then
bar.BackgroundColor3 = Color3.fromRGB(163, 108, 30);
elseif bar.Size.X.Scale > 0 and bar.Size.X.Scale < 0.25 then
bar.BackgroundColor3 = Color3.fromRGB(170, 0, 0);
end
enpiesie
(enpiesie)
5
The code is only running once.
To make it run indefinitely, simply put the if statement in a while loop
while wait() do
--your code here
end
2 Likes
Kryptalys
(Kryptalys)
6
Thank you so much. I can’t believe I didn’t catch that my self. That worked.
Have a great Day/Afternoon/night.
1 Like
enpiesie
(enpiesie)
7
No worries dude, I forget that a lot as well xD