I’ve made a data store script that is supposed to save 1 value ( inside Replicated Storage.
It prints not saved and doesn’t save a color3 value inside a folder and I’ve been trying for hours.
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AmbientData = DataStoreService:GetDataStore("AmbientData")
PlayersService.PlayerAdded:Connect(function(Player)
local PlayerDataFolder = ReplicatedStorage:WaitForChild(Player.Name)
print(PlayerDataFolder)
local Data
local success, errormessage = pcall(function()
Data = AmbientData:GetAsync(Player.UserId .. "-AmbientData")
end)
if success then
PlayerDataFolder.Data.Ambient.Value = Color3.fromRGB(Data)
print(Color3.fromRGB(Data))
else
print("no ")
end
end)
PlayersService.PlayerRemoving:Connect(function(Player)
local PlayerDataFolder = ReplicatedStorage:WaitForChild(Player.Name)
local success, errormessage = pcall(function()
AmbientData:SetAsync(Player.UserId .. "-AmbientData", PlayerDataFolder.Data.Ambient.Value)
end)
if success then
print("saved")
else
print("not saved")
end
end)```
does the first print works ? Problem is prob as said before, you can’t store a color3 value. If you want to store the color 3, you would need to store a table with the RGB of the color.
You are not able to save Color3 values inside of datastores since datastores only accept UTF-8 characters. You would have to come up with a way to save the values separately and put them together when loading data. Maybe try using a table with R,G,B set to an integer.
Something on the lines of this:
local Data = {
["Ambient"] = {
["R"] = 215,
["G"] = 215,
["B"] = 215,
}
}
-- get data, then combine values
local GotData = DATASTORE:GetAsync() -- get async call
-- combine integers to make color
Object = Color3.fromRGB(GotData["Ambient"]["R"],GotData["Ambient"]["G"],GotData["Ambient"]["B"])
This isn’t Python where arrays and dictionaries are two different types. You can save a dictionary just as you can save an array.
You just can’t save a hybrid of arrays and dictionaries.
A table and a dictionary are the same things the only difference you can make is of indexes between arrays and dictionaries in Lua, both still considered tables which you can save easily in Roblox.
Only strings can be saved to what DataStoreService interfaces with (tables internally being JSONEncoded).
Edit: Rather than waiting for replies, you could just test out a theory yourself instantaneously getting the results.
If it’s a Color3 Value you’re trying to save, you could serialize it
local color = Color3.fromRGB(100,210,244)
--> equivalent to Color3.new(100/255, 210/255, 244/255)
-- printing color.R would output the value color.R/ 255, since the value returned would've been scaled to a maximum of 1 (representing 255)
local function toSaveable(color)
return {R = color.R * 255, G = color.G * 255, B = color.B * 255}
end
-- save
DataStore:SetAsync(key, toSaveable(color))
-- retrieve
local color = DataStore:GetAsync(key)
color = Color3.fromRGB(color.R, color.G, color.B)
-- or just have the function return the same color.R, color.G, color.B values and construct using Color3.new(color.R, color.G, color.B) instead of multiplying and constructing using Color3.fromRGB