Color3 new not converting to RGB properly?

I want to convert Color3.new to Color3.fromRGB (I’m more comfortable with fromRGB). I was able to get the right method of converting with some help, but Studio still reads it as a Color3.new.
My code:

local toAdd = Color3.new(0, 0, 0)
for i, v in pairs(color.Keypoints) do
	toAdd = Color3.new(toAdd.R+v.Value.R, toAdd.G+v.Value.G, toAdd.B+v.Value.B)
end
local r = ((toAdd.R*255)/#color.Keypoints)
local g = ((toAdd.G*255)/#color.Keypoints)
local b = ((toAdd.R*255)/#color.Keypoints)
print(r, g, b, "Expected output") --Expected output
local returnThis = Color3.fromRGB(r,g,b)
print(returnThis.R, returnThis.G, returnThis.B, "Returned") --What is given

Output:

 11:54:48.571 | 205.06323158741 144.5982465148 205.06323158741 Expected output  -  Client - MainModule:46
 11:54:48.571 | 0.8041695356369 0.56705194711685 0.8041695356369 Returned  -  Client - MainModule:48

I believe this is because Color3 properties still use the Color3.new range.

Is there any way to fix this? I set it to Color3.fromRGB(r,g,b) in my code above, why is it still reading as Color3.new?

Because that’s just how Color3s work, fromRGB just converts from the 0-256 range to the 0-1 range. If you want the 0-255 value, either convert it back or use the r, g, and b variables you already have.

really? so I have to use Color3.new instead when returning it???

No, you can use fromRGB to construct the color3.

So basically fromRGB is just like a function that turns it to a Color3.new?

1 Like