I want to make an avatar editor with support of limb colors, but I get an error: “Color3 expected, got table”. Here is my code for returning the body color:
functions.GetBodyColor.OnServerInvoke = function(plr, typeOfObj)
if typeOfObj == "Head" then
return CharDS:GetAsync(plr.UserId.."-headcolor")
elseif typeOfObj == "Torso" then
return CharDS:GetAsync(plr.UserId.."-torsocolor")
elseif typeOfObj == "LeftArm" then
return CharDS:GetAsync(plr.UserId.."-leftarmcolor")
elseif typeOfObj == "LeftLeg" then
return CharDS:GetAsync(plr.UserId.."-leftlegcolor")
elseif typeOfObj == "RightArm" then
return CharDS:GetAsync(plr.UserId.."-rightarmcolor")
elseif typeOfObj == "RightLeg" then
return CharDS:GetAsync(plr.UserId.."-rightlegcolor")
end
end
and here is my code for setting the BackgroundColor3 to what we have in the DataStore.
It’s exactly what the error is saying - your datastore is returning a table, not a Color3. You need to convert your table data into a Color3 before assigning it to the BackgroundColor3 property.
Oh, alright, so basically I would just get [1], [2], and [3], then I would turn that into R, G, B? Never did this before, just getting confirmation before I do that.
Depends on how you’re storing it in your datastore. If it is just a numeric index (e.g. 1, 2, 3), then yes you would just load it into a Color3 like this example:
local data = CharDS:GetAsync(plr.UserId.."-headcolor")
return Color3.new(data[1], data[2], data[3])
Or if you’re really fancy, you could use unpack to do the same thing:
local data = CharDS:GetAsync(plr.UserId.."-headcolor")
return Color3.new(unpack(data))
I prefer the first way though, because it’s more explicit with what is happening.
You should also note that unpack() is no longer a thing in newer verisons of Lua but you can still use it because Roblox Studio uses an old verison of Lua, so it’s better to use table.unpack() than unpack() now because it’s good practice and it does the exact same thing since unpack is only available in older verisons of Lua and not the newer verisons of Lua.