R cannot be assigned to

Hello, I am trying to make a saving color3 value in a table with other values but I get the error “R cannot be assigned to”. Here is the part of the script with the error:

local s = saves["colourTheme"]                                          
local R,G,B = string.split(s,"!")[1],string.split(string.split(s,"!")[2],"?")[1],string.split(string.split(s,"!")[2],"?")[2]
print(string.sub(R,1,1))--Prints "0" -- correct string
colourTheme.Value.R = tonumber(string.sub(R,1,1))

colourTheme is the color3 value. Any help will be appreciated.

You need to set Color3Value.Value to a Color3 like this:

colourTheme.Value = Color3.new(0, 0, 0)
1 Like

This made the error not happen but now when I change the value its completely different:

print(tonumber(R),tonumber(G),tonumber(B)) -- prints 85 255 255 (correct)
colourTheme.Value = Color3.new(tonumber(R),tonumber(G),tonumber(B)) --changes

image(Noticed a pattern and divided by 255 nevermind )

Those are Color3.fromRGB() values, which are in the range of 0-255, Color3.new() values are in the range of 0-1 instead.

You need to divide those 3 values by 255 before you pass them as arguments to the Color3.new() constructor function.

colourTheme.Value = Color3.new(tonumber(R/255),tonumber(G/255),tonumber(B/255)) --changes
1 Like

Ye, I have already done this. limit

Well, im a bit late with the answer but:
I used your solution and discoverd that you don’t need to divide the values by 255.
Just R, G and B are good enough.

I’d avoid using RGB values within the range of 0-255 (even if they work), Color3Values expect RGB values in the range of 0-1.

https://developer.roblox.com/en-us/api-reference/class/Color3Value