local saveslot1 = game:GetService("DataStoreService"):GetDataStore("SlotSave100")
function SaveData1(player,character)
local face
local skincolor
for i,v in pairs(player.Character.Head:GetChildren()) do
if v:IsA("Decal") then
face = v
end
end
for f,k in pairs(player.Character:GetChildren()) do
if k:IsA("MeshPart") then
skincolor = k
end
end
local charactercustom = {
["Face"] = face.Texture,
["SkinColor"] = {skincolor.Color.r,skincolor.Color.g,skincolor.Color.b}
}
local suc,err = pcall(function()
saveslot1:SetAsync(player.UserId,charactercustom)
end)
print(player.Name, "DataStoreRetrivalInformation", suc, err)
end
function LoadData1(player,Character)
local charactercustom
local suc,err = pcall(function()
charactercustom = saveslot1:GetAsync(player.UserId)
end)
if charactercustom then
print(player.Name, "DataStoreRetrivalInformation", suc, err)
for i,v in pairs(player.Character.Head:GetChildren()) do
if v:IsA("Decal") then
v.Texture = charactercustom["Face"]
end
end
for i,v in pairs(Character:GetChildren()) do
if v:IsA("MeshPart") then
v.Color = Color3.fromRGB(charactercustom["SkinColor"][1],charactercustom["SkinColor"][2],charactercustom["SkinColor"][3])
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
--repeat wait() until player.Character
player.CharacterAdded:Connect(function(char)
LoadData1(player,char)
end)
end)
game:BindToClose(function()
for _,player in pairs(game.Players:GetPlayers()) do
SaveData1(player)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
--repeat wait() until plr.Character
local char = plr.Character or plr.CharacterAdded:Wait()
SaveData1(plr,char)
end)
I want to save the Color3 values to datastores. It saves but when I look at the array in DataStore Editor, it shows a bunch of random numbers instead of the actual Color3 values.
--Save to datastore
local SaveColor3 = Color3.new()--color3 to save
local SaveToDatastore = {SaveColor3.R,SaveColor3.G,SaveColor3.B} --save to datastore
datastore:SetAsync(key,SaveToDatastore)
--Load from datastore
local DataFromDatastore = datastore:GetAsync(key) --load from datastore
local LoadedColor3 = Color3.new(DataFromDatastore.R,DataFromDatastore.G,DataFromDatastore.B)
When you ask a Color3 component (R,G,B property) they don’t return their usual 0-255 range.
If you insert a Part and print(workspace.Part.Color.R) you’re going to get a decimal number in the output. You’d need to convert that into it’s original 0-255 range.
local LoadedCustom = saveslot1:GetAsync(player.UserId)
local SkinColor = LoadedCustom["SkinColor"]
local LoadedColor3 = Color3.fromRGB(SkinColor[1] * 255, SkinColor[2] * 255, SkinColor[3] * 255)
Currently you set all the parts to the same colour, so you’d just do that for each property of BodyColors. There’s six properties so it would be six lines of code for the setting:
local loadedColor = Color3.new(charactercustom.SkinColor[1], charactercustom.SkinColor[2], charactercustom.SkinColor[3])
local bodyColors = Character:WaitForChild("Body Colors")
-- Set the properties
bodyColors.HeadColor3 = loadedColor
bodyColors.LeftArmColor3 = loadedColor
bodyColors.LeftLegColor3 = loadedColor
bodyColors.RightArmColor3 = loadedColor
bodyColors.RightLegColor3 = loadedColor
bodyColors.TorsoColor3 = loadedColor
I think you would need to save all links (meshlinks for example), texturelinks etc. I would save these as a string and all positions as numbers (or Vector3 values) and then just, when you are creating a new accessory, use these strings. This should not be to hard. Make sure to save everthing separately.