Hey, before you say, I know how datastores work, but I’m unsure how to save the entire player, for example:
If the player has like 6 accessories, I cant simply write a variable and save it with the ID and load it, cause each player has different amounts of accessories, how can I save the accessories, shirt, pants, face, and about that mostly.
HumanoidDescription. It’s perfect for applying hats, limb colors, accessories, and apparel, among other things. You could use Players:GetHumanoidDescriptionFromUserId to save it to the datastore, then use player:LoadCharacterWithHumanoidDescription(humanoidDescription) to load it in with the humanoid description.
I attempted to save the HumanoidDescription to the datastore, even when using game.Players:GetHumanoidDescriptionFromUserId, it still thought of it as an instance and rejected saving it.
local DataStoreService = game:GetService("DataStoreService")
local CharacterDataStore = DataStoreService:GetDataStore("CharacterDataStore")
game.Players.PlayerAdded:Connect(function(plr)
wait(1)
local Username = plr.Name
local UserID = plr.UserId
local SetCharacter
local data
local success, errormessage = pcall(function()
data = CharacterDataStore:GetAsync(plr.UserId.."-HumanoidSave")
end)
if success then
SetCharacter = data
print("Test | It Loaded!")
else
print("Error while getting character data")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local HumanoidSave = game.Players:GetHumanoidDescriptionFromUserId(player.UserId)
local success, errormessage = pcall(function()
CharacterDataStore:SetAsync(player.UserId.."-HumanoidSave", HumanoidSave)
end)
if success then
print("Data successfully saved!")
else
print("There was an error while saving the data")
warn(errormessage)
end
end)
I think this is a very bad idea for saving/loading character appearances, the accessories are randomized each time, and this is a very hard way to go by it.
I checked the post, you sure it isnt a wikipedia page? Im sorry but I simply will not read multiple paragraphs on a subject that Im not even familar with.
Could you give me a basic example of a code snippet on how this would work with saving avatars, (shirts, pants, accesories, etc)? Cause I am quite stuck
Im sorry I meant serializing, like my previous method was to use HumanoidDescription, save it, and apply it to the user, but how can this be done with seriazling?
function TurnToSaveableObj(Accessory,propstosave)
if Accessory:IsA("Accessory") then
local returnthing = {}
for _,v in pairs(propstosave) do
returnthing[v] = Accessory[v]
end
return returnthing
end
end
--example:
TurnToSaveableObj(uraccessoryobj,{"Name"} --[[props to save, u dont need to save name though.]]}
--deserialize
local newAccessory = Instance.new("Accessory")
for property,v in pairs(serializeddata) do
newAccessory[property] = v
end
I believe someone else can explain it better as im not so experienced of accessories.
local DS =game:GetService("DatastoreService"):GetDatastore("Your_Name_Here")
function SaveData(Player)
--Your Player Directory/Defination
--Any Other Values like Coins etc.
local Char = Player.Character
local Values = Player.Values:GetChildren() --example
local tabletosave
local Humanoiddescription = Char.Humanoid:GetHumanoidDescription() -- so it depends here if you want to save user id then do :GetHumanoidDescriptionFromUserId
Table["HatOrWhatever"] = Humanoiddescription.WhateverUWannaSave
--Repeat the above for all accessories. Now for Extra Accessory just create another one and if it doesn't exist make it "None".
--Now Just Save I'm on mobile so I can't write much as it's tedious but I think u get the point.
end