How to Save/Load character appearances with DataStore?

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.

Sorry for the inconvience.

1 Like

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.

2 Likes

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)

Sorry if it doesnt look good, I’m still learning :sweat:

1 Like

serialization

Save the needed properties of the accessory and load it using serialization

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.

1 Like

Its the exact opposite.

No it is not. If you save the properties you are randomizing and the essential, its not a problem.

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.

1 Like

Nope. Its a devforum post link A tutorial.

1 Like

Is there any other way we can come by this than serializing it?

Yes but its inefficient.

Trust me, serializing will be very easy, easier and more practical than what im about to tell you.

A table with all the property settings like this

local yes = {
   Coolhatone = {props},
   Coolhattwo = {props}
}
-- so tedious to manually add them
1 Like

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

Before that, tell me the properties your randomizing and ill give an example functions.

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?

1 Like

Alrighty then.

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


1 Like