Saving player character to a DataStore?

I’ve intentionally avoided touching DataStores for a while, since this kind of thing scares me, but earlier today, I gained some level of hubris, and like the protagonist of an ancient Greek tragedy, I am beginning to think I was right to be afraid.

Essentially, I want to store [X PLAYER’S] character model (or just appearance) to a DataStore, but I have absolutely no idea how to do this. The important part here is their hats - I cannot use HumanoidDescription because HumanoidDescription does not work with custom accessories, ones which are not on the ROBLOX catalog. Since I don’t have access to UGC, but accessories are very convenient, I’ve been using that Object type for a lot of character morphs.

I’ve tried looking through DevForum and Youtube for anyone who’s done something similar, but the one instance I found was a guy asking a similar question, and then going, “I realized this was stupid, and don’t want to do it anymore.”

I’m not looking for anyone to write a script or anything - just trying to understand the methodology behind doing something like this.

I will suppose you already have knowleadge on how DataStores work to keep the post short.
The player character will always be the same when joining a game, either a r6 or r15. The only thing that changes is the accesories,shirt,pants, and body colors so you would only need to save and load those. That can be achieved with the following table:

local CharaterData = {shirt,pants,bodycolors,accessories}

Now, how does each one of those things gets loaded to the player? Lets start with the easy ones.

Shirts and Pants

Shirts and pants load using an id so saving and loading them would be as easy as saving the id like this:

CharacterData.shirt = 123456789 --example id
CharacterData.pants = 123456789 --example id

but since roblox gets the shirt/pants from this link: http://www.roblox.com/asset/?id={id} you can also save them link this:

CharacterData.shirt = "http://www.roblox.com/asset/?id=123456789"  
CharacterData.pants = "http://www.roblox.com/asset/?id=123456789"  

the first method is prettier but involves getting rid of the url when saving and adding the url to the string when loading but at the end both of them work.
To get the id would be something like this:

game.Players.PlayerAdded:Connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:Wait()
    local shirturl = char:WaitForChild("Shirt").ShirtTemplate
end)
Body color

Now skin color is easy as well but has to many properties so we are going to make another table for each body part.

local bodycolors = {HeadColor,LeftArmColor,LeftLegColor,RightArmColor,RightLegColor,TorsoColor}

to color the parts you can use BrickColor or Color3 objects but for simplicity im going to use BrickColor so if we continue the function we had with the character as char we can do:

bodycolors.HeadColor = char:WaitForChild("Body Colors").HeadColor
--and so on for the other 5
--and then save the data to the initial table
CharacterData.bodycolors = bodycolors

and to load the data we would do

character["Body Colors"].HeadColor = BrickColor.new(CharacterData.bodycolors.HeadColor)
--and so on for the other 5
Accessories

Here comes the hardest part, i have never saved the player character so maybe i could be wrong somewhere.
to know how to save accessories first we need to know what and accessory is. An accessory is a roblox class, which means that every accesory instance will have the same properties that can be changed individualy. Knowing this we can save the properties we want and load them back again.

lets start with how the accessory is composed. Every accesory needs the following:
-The accessory object
-The handle which is a meshpart most of the times
-An attatchment
-A weld

im going to start from the easies ones to the hardest.
The weld can be saved and loading with Instance.new(“WeldConstraint”) whose part0 is the Handle and part1 the part it is attatched to (can be head or anything).

The attatchment is like the Weld, just that its name must be the same as the Attatchment is attatching to (examples are HatAttatchment,FaceFrontAttatchment etc) and need to have a position as well as an orientation which both are a vector3 value

The accessory object has 4 properties: AttatchmentForward, AttatchmentPos, AttatchmentRight, AttatchmentUp. To be honest i don’t know what this propiertes actually do again due to my lack of experience working with accessories but if needed you can save them and load them.

And finally, the hardest part: The meshpart is the body of the accessory, is the one that combines everything to make a beatiful looking bacon hair. This one has so many propierties but we don’t need all of them, we just need the following:

-MeshId
-TextureId

Since the attatchment is doing the position and orientation task we are just left with the visual thing, for this we need to save the meshid url and the textureid url and load them the same way that we have done before using yet another table. At this point you could already make your own table will all the propiertes i already listed

just remember to create the instances of every object i mentioned before, shirt, pants, weld, attatchemnt etc.

As a conclusion to this long post that somehow i managed to write, doing this is easier that i though it would be, is just a matter of finding the right way to do so which i think i got, there could be ways to improve the method but as a basic example that works perfectly fine. I hope you find this useful and thanks for giving me something to do for the past 30 minutes i was really bored.

6 Likes

Thank you! You gave me just the right push I needed to actually be able to save what was important into a serialized table.
This post was also a big help.

2 Likes