local Players = game:GetService("Players") -- player.Parent
local Datastore = game:GetService("DataStoreService")
Datastore = Datastore:GetDataStore("colors")
-- other code
Players.PlayerRemoving:Connect(function(player)
local ok, eror = pcall(function()
Datastore:SetAsync((Color.R,Color.B,Color.G),player.info.color.Value)
end)
if not ok then
print(eror) -- line that errors
end
end)
local Players = game:GetService("Players") -- player.Parent
local Datastore = game:GetService("DataStoreService")
Datastore = Datastore:GetDataStore("colors")
local function Serialize(color)
local r,g,b = color.R,color.G,color.B
return r..","..g..","..b
end
local function Deserialize(colorstring)
local r,g,b = colorstring:split(",")[1],colorstring:split(",")[2],colorstring:split(",")[3]
return Color3.new(tonumber(r),tonumber(g),tonumber(b))
end
Players.PlayerRemoving:Connect(function(player)
local ok, eror = pcall(function()
Datastore:SetAsync(pleyer.Name,Serialize(player.info.color.Value))
end)
if not ok then
print(eror) -- line that errors
end
end)
Players.PlayerAdded:Connect(function(player)
local ok, eror = pcall(function()
return Datastore:GetAsync(pleyer.Name)
end)
if ok then
print(Deserialize(eror))
end
end)
Errr, I canāt really test anything because A: I am busy and B: I am lazy. But:
Players.PlayerAdded:Connect(function(player)
local ok, eror = pcall(function()
return Datastore:GetAsync(player.Name)
end)
if ok then
print(Deserialize(eror))
end
end)
Players.PlayerAdded:Connect(function(player)
local ok, eror = pcall(function()
return Datastore:GetAsync(player.Name)
end)
if ok and eror then
print(Deserialize(eror))
end
end)
Youāre looking for the term āSerializationā.
Hereās the most efficient way of converting a Color3 data type to table format:
local function serializeColor(color: Color3)
local r, g, b = color.R, color.G, color.B
r, g, b = math.floor(r * 255), math.floor(g * 255), math.floor(b * 255)
return {r, g, b}
end
local function deserializeColor(serialzedColor: any)
local r, g, b = serialzedColor[1], serialzedColor[2], serialzedColor[3]
return Color3.fromRGB(r, g, b)
end
local serialized = serializeColor(COLOR)
local deserialized = deserializeColor(serialized)
local Players = game:GetService("Players") -- player.Parent
local Datastore = game:GetService("DataStoreService")
Datastore = Datastore:GetDataStore("colors")
-- other code
Players.PlayerRemoving:Connect(function(Player)
local Color = Color3.new(1,1,1)
local ok, eror = pcall(function()
Datastore:SetAsync(Player.UserId,Color.R.."/"..Color.G.."/"..Color.B)
end)
if not ok then
print(eror) -- line that errors
end
end)
Players.PlayerAdded:Connect(function(Player)
local Return = Datastore:GetAsync(Player.UserId)
if type(Return) == "string" then
local ColorReturned = {}
for i,v in pairs(string.split(Return,"/")) do
if i == 1 then
ColorReturned["R"] = v
end
if i == 2 then
ColorReturned["G"] = v
end
if i == 3 then
ColorReturned["B"] = v
end
end
local ColorReturnedComplete = Color3.new(ColorReturned["R"],ColorReturned["G"],ColorReturned["B"])
else
print("No Saves")
end
end)
What kind of human are youā¦ please stay a mile away from me, from now on. As:
local Players = game:GetService("Players") -- player.Parent
local Datastore = game:GetService("DataStoreService")
Datastore = Datastore:GetDataStore("colors")
-- other code
Players.PlayerRemoving:Connect(function(Player)
local Color = Color3.new(1,1,1)
local ok, eror = pcall(function()
Datastore:SetAsync(Player.UserId,Color.R.."/"..Color.G.."/"..Color.B)
end)
if not ok then
print(eror) -- line that errors
end
end)
Players.PlayerAdded:Connect(function(Player)
local Return = Datastore:GetAsync(Player.UserId)
if type(Return) == "string" then
local ColorReturned = string.split(Return,"/")
-- could be like this ngl
else
print("No Saves")
end
end)