Color3's work on a scale of numbers between 0-1. Since most people like to use a scale of 0-255, we need to divide every number by 255 to make it fit into the Color3's requirements.
So, let's make ourselves a function that will return a Color3 with each number divided by 255.
function ChangeColor3(r,g,b)
return Color3.new(r/255,g/255,b/255)
end
Now, we can apply the function like so:
script.Parent.TextColor3 = Change(255,58,65)
Finally, let's put it all together! Also, you don't need to wait while changing each property, just do it instantly and it'll work fine.
local score = game.ServerScriptService.MainGame:WaitForChild("score1")
local score2 = game.ServerScriptService.MainGame:WaitForChild("score2")
function ChangeColor3(r,g,b)
return Color3.new(r/255,g/255,b/255)
end
while wait() do
if score2.Value > score1.Value then
script.Parent.TextColor3 = ChangeColor3(72,255,46)
script.Parent.Text = "Winning"
elseif score2.Value < score1.Value then
script.Parent.TextColor3 = ChangeColor3(255,58,65)
script.Parent.Text = "Losing"
elseif score2.Value == score1.Value then
script.Parent.TextColor3 = ChangeColor3(124,156,255)
script.Parent.Text = "Tied"
end
end
We can improve the script by making the code a function and then connecting it to the Changed function of each score value.
Final code:
local score = game.ServerScriptService.MainGame:WaitForChild("score1")
local score2 = game.ServerScriptService.MainGame:WaitForChild("score2")
function ChangeColor3(r,g,b)
return Color3.new(r/255,g/255,b/255)
end
function updateScore()
if score2.Value > score1.Value then
script.Parent.TextColor3 = ChangeColor3(72,255,46)
script.Parent.Text = "Winning"
elseif score2.Value < score1.Value then
script.Parent.TextColor3 = ChangeColor3(255,58,65)
script.Parent.Text = "Losing"
elseif score2.Value == score1.Value then
script.Parent.TextColor3 = ChangeColor3(124,156,255)
script.Parent.Text = "Tied"
end
end
score.Changed:connect(updateScore)
score2.Changed:connect(updateScore)
I hope my answer helped you. If it did, be sure to accept it.
3 comments
I advise against calling your function
Color3. This will cover up the actualColor3, and make it so that code wanting to use the normalColor3.newconstructor won't be able to. I suggest usingColorinstead. (Also your code as written won't work because the global variable will overshadow the Color3 anyway)That makes sense. I'll change this now.
Thanks!