Save players accessories

Hello, i have a character customization system for my game and i want to be able to save the player accessories when the leave the game and load them back when they join. Can anyone help me?

You’d need to have a folder in ServerStorage for all possible hats in your game, and when the player is rejoining, check in their data if they have any data, if they have hats [saved as strings/bools], then get that from that folder and clone it into the player’s ‘OwnedHats’ Folder.

To save the hats, you’ll need to save the names of those hats in strings, which later [when rejoined], you’ll use this to clone the actual hats from the folder in server storage.

this is gonna require scripting, so if you’re not up for that, give up and move on. otherwise…

to save accessories that exist in the Avatar Shop:

each item in roblox’s avatar shop has an ID associated with it. save the player’s accessory IDs in a DataStore when the player leaves. then, when the player joins the game later, you’ll need to create and use a HumanoidDescription, load all the IDs from the DataStore and input the IDs of all the hats, shirts, etc. into the HumanoidDescription instance. then, somewhere in a script, you need to manually load the character by doing something like:

local player = (put your player here)
local avatarAccessories = (reference your humanoid description here)
player:LoadCharacterWithHumanoidDescription(avatarAccessories)

this will spawn your character with all the accessories and shirts and stuff that you want.

  1. Put all of the accessories in a folder in the ServerStorage (make sure they all have unique names!)

  2. Have a script which saves the accessories the player has into a table, and then JSONing it into a string to be stored in a StringValue, which can then be saved by using DataStore.

  3. Have another script (can be in the same script as before!) where it JSONs it back into a Lua table, and then use a loop to check each accessory in the ServerStorage if their name is stored inside the table.

  4. If it is in the table, have it give the player the accessory using “humanoid:AddAccessory(accessory_path)”

You’ll probably need datastore for that.