Currently having trouble with saving brickColors and Color3s in my datastore, and I really want to save them.
The reason for this, is I am planning on having character customization in my game tonight, such as color customization and such, but I keep getting the 104 error. Cannot Save Color3/BrickColor in DataStore.
function getSaveableColor3(color)
return {r = color.r, g = color.g, b = color.b}
end
function loadColorFromDataStore(t)
return Color3.new(t.r, t.g, t.b)
end
if you do want strings for whatever reason, converting to hexadecimal is useful
local function colorToString(color)
local r = math.floor(color.r*255+.5)
local g = math.floor(color.g*255+.5)
local b = math.floor(color.b*255+.5)
return ("%02x%02x%02x"):format(r, g, b)
end
local function stringToColor(hex)
local r, g, b = hex:match("(..)(..)(..)")
r, g, b = tonumber(r, 16), tonumber(g, 16), tonumber(b, 16)
return Color3.fromRGB(r, g, b)
end
In reference to @EchoReaper’s solution, I’m getting an error where value doesn’t exist allegedly.
I’ve posted the offending code segment below if anyone wants to help.
val.Parent=folder
val.Changed:Connect(function()if save then
local function getSaveableColor3(val)
return {r = val.Value.r, g = val.Value.g, b = val.Value.b}
end
local function loadColorFromDataStore(t)
return Color3.new(t.r, t.g, t.b)
end
Honestly not sure what to do if I can’t get one of these methods to work.
This is not enough information to go on. Please create a minimal repro file that has just the save/load color functionality and simple DataStore code (do not dump your whole game or script, as no one will want to read through the whole thing). As you create the minimal repro file, you’re more than likely find what the problem is, but if not, then it’s simple enough that someone can point out what you’re doing wrong.
Here is a simplified version of the entire color storing thing.
Still the same error as described in my previous post.
local DS=game:GetService"DataStoreService":GetDataStore("PlayerCustomization","global")
game:GetService"Players".PlayerAdded:Connect(function(p)
local val = Color3.new(255,255,255)
local function getSaveableColor3()
return {r = val.r, g = val.g, b = val.b}
end
local function loadColorFromDataStore(t)
return Color3.new(t.r, t.g, t.b)
end
save=false;DS:SetAsync(p.UserId..getSaveableColor3())
delay(6,function()save=true;end)
end)
Edit:
Changed it a bit and now I’m getting this error:
[ServerScriptService.DataStores.PlayerCustomizationDataStore:35: attempt to concatenate a table value])
I’ve never messed with return functions to be honest.
Edit:
It seems I’m one step closer to solving this. However, I’m getting a strange Color3 value that is black with numbers that appear to be 6365, 6365, 6365. What’s going on here?
local DS=game:GetService"DataStoreService":GetDataStore("PlayerCustomization","global")
game:GetService"Players".PlayerAdded:Connect(function(p)
local val = Color3.new(255,255,255)
local function getSaveableColor3()
return {r = val.r, g = val.g, b = val.b}
end
local function loadColorFromDataStore()
return Color3.new(val.r, val.g, val.b)
end
local data=loadColorFromDataStore()
local folder = Instance.new("Folder")
folder.Name = "PlayerCustomization"
folder.Parent = p
local val = Instance.new("Color3Value")
val.Parent = folder
val.Name = "PrimaryColor"
val.Value = data
save=false;DS:SetAsync(p.UserId, getSaveableColor3(val))
delay(6,function()save=true;end)
end)
Color3.new takes values on a scale of [0,1]. If you want to use the scale of [0,255], you need to use Color3.fromRGB. Example: local val = Color3.fromRGB(255,255,255)
local DS=game:GetService"DataStoreService":GetDataStore("PlayerCustomization","global")
game:GetService"Players".PlayerAdded:Connect(function(p)
local val = Color3.fromRGB(255,255,255)
local function getSaveableColor3()
return {r = val.r, g = val.g, b = val.b}
end
local function loadColorFromDataStore()
return Color3.fromRGB(val.r, val.g, val.b)
end
local data=loadColorFromDataStore()
local folder = Instance.new("Folder")
folder.Name = "PlayerCustomization"
folder.Parent = p
local val = Instance.new("Color3Value")
val.Parent = folder
val.Name = "PrimaryColor"
val.Value = Color3.fromRGB(loadColorFromDataStore())
val.Changed:Connect(function()
save=false;DS:SetAsync(p.UserId, getSaveableColor3(r, g, b))
delay(6,function()save=true;end)
end)
end)
If you look at the functions I originally posted, getSaveableColor3 takes one argument, “color”. You’re passing it three (r, g, and b), which aren’t defined as variables anywhere – they’re nil, and you removed the parameter in the function definition. When you construct a Color3 with nil arguments, it spits out black.
This is seeming less and less like you need help saving color3 values in DataStores, and more like you need help understanding all prerequisite knowledge necessary to implement this. I encourage you to watch these tutorials by AlvinBlox:
If you still have questions after watching those, feel free to ask here, but these should help out a lot.