At this point I’ve willing to pay someone to help me with this.
I currently have a DataStore that is capable of saving all int; string; bool values within a specific PlayerFolder - However, I’m sincerely struggling to implement a method of saving Color3s - Despite reading the Wiki multiple times - I am able to recreate a singular DS for the specifics. However, I’m looking into adding it into my own overall.
If anyone could help I’ll be grateful. But as I said, also willing to pay at this point.
DataSave
function System.DataSave(Player)
local success, Data = pcall(function()
return DataStoreService:SetAsync(Player.UserId, saveToDictionary(Player["PlayerData"]))
end)
if success then else end
end
function saveToDictionary(object)
if not object:IsA("Configuration") then
return object.Value
else
local newTable = {}
for i,v in pairs(object:GetChildren()) do
newTable[v.Name] = saveToDictionary(v)
end
return newTable
end
end
DataLoad
function System.DataLoad(Player)
local success, Data = pcall(function()
return DataStoreService:GetAsync(Player.UserId)
end)
if success then
if Data then
local PlayerData = materializeDictionary(Data)
PlayerData.Name = "PlayerData"
PlayerData.Parent = Player
PlayerData["isNew"].Value = false
else
local PlayerData = script["Template"]:Clone()
PlayerData.Name = "PlayerData"
PlayerData.Parent = Player
PlayerData["isNew"].Value = true
end
end
end
function materializeDictionary(input)
if typeof(input) == "table" then
local newConfig = Instance.new("Configuration")
for i,v in pairs(input) do
local newObject = materializeDictionary(v)
newObject.Name = i
newObject.Parent = newConfig
end
return newConfig
elseif typeof(input) == "number" then
local newIntValue = Instance.new("NumberValue")
newIntValue.Value = input
return newIntValue
elseif typeof(input) == "string" then
local newStringValue = Instance.new("StringValue")
newStringValue.Value = input
return newStringValue
elseif typeof(input) == "boolean" then
local newBoolValue = Instance.new("BoolValue")
newBoolValue.Value = input
return newBoolValue
end
end
My apologies if I’m misunderstanding. Can you not save Color3 values in a datastore?
If not, you could save a table with 4 elements as such:
local tbl = {"Color3",1,0,0} --value for red (255,0,0)
You can detect that it’s a color3 by using “if tbl[1] == “Color3” then”, and then use the other 3 elements as the value.
I was pretty sure you could store Color3’s on their own though, so a table with 1 or 2 elements should work fine. Is the problem that you don’t know how to detect whether something is a Color3 value?
Please refrain from super tiny and small responses, whilst being brief.
You can actually not save Color 3 through DataStore, you would need a Table, as @doggy00 said & @NeonD00m , you could something like this;
--Save
--Save your data here
local Color = Color3.new(0 , 0 , 0) --example
local RGBData = {
R = Color.R
G = Color.G
B = Color.B
}
Loading;
--Load
--Load your data with your method of choice
local Data = Data --whatever method you're using
local RBG = Instance.new("Color3Value")
local ColorFromData = Color3.new(Data.R , Data.G , Data.B)
RBG.Value = ColorFromData
What we’re doing is saving the Color3 value in a table, basically the same as @doggy00 is doing, but listing it off cleaner, you could easily mark the tables and make more and save them bulk.
It seems you misunderstood me.
I meant using Color3.new instead of Color3.fromRGB, not necessarily using a Color3Value. It’s a mistake I once made and it took me hours to figure out I wasn’t using Color3.fromRGB.
I can assure you 100% that I was not confused while reading your message. I fully understand that fromRGB is better to be used in this instance but I am only showing him how to save the data how he asked, however he wants to load the data is up to him.
I believe I’ve done something like this in the past:
-- convert Color3 to table
local SaveColour = tostring(Color3.new()):split(", ")
-- convert table back to Color3
local LoadColour = Color3.new(unpack(SaveColour))
You could save the three color components R,G,B (multiplied by 255) as a hexadecimal string of exactly six characters:
local colorAsHexString = "f0f0f0"
local r = tonumber(colorAsHexString:sub(1,2), 16)
local g = tonumber(colorAsHexString:sub(3,4), 16)
local b = tonumber(colorAsHexString:sub(5,6), 16)
print("RGB:",r,g,b)
local color = Color3.fromRGB(r,g,b)
print("Color3:",color)
local hexString = ("%02x%02x%02x"):format(color.R*255, color.G*255, color.B*255)
print("Hexadecimal:",hexString)