How would i go about saving a character?

so im trying to make my character save but i have pretty much no clue how. theres also no kind of wiki about saving objects could somebody please explain me how i would make a system like this?
i tried to make it myself but it diddnt really make sense to me how i would make a object a number or however u do this :stuck_out_tongue: i can however make a value and do if value == 1 then let the person wear that hat or hair but it seems very inefficient

If you’re talking about saving things, try datastore. Usually used to help save things, might be the thing you’re looking after for.

Wiki if you need it: https://developer.roblox.com/articles/Data-store

ik how to save things but not character
the wiki is for how to setup a datastore

Actually, someone has actually talked about this question of how to save objects : Saving parts/models via datastore?

Hopefully that would help if you need to save objects and characters.

i tried it but diddnt work sighs anyway im more focusing on saving the character not really a object

What are you saving on the character, I’ve found that I can easily get away with saving a string version of what I want to save to the datastores

Example say we have a 1 part, and all you want to save is it’s size
well you could compile it into a string so it may look like this “Part SizeX: 2 SizeY: 2 SizeZ: 2” and then save that to the datastore then when you’re ready to, take the string and use String Manipulation to plug that info back into a part, etc…

So if we’re interested in saving clothes for a character what we can do is get what the clothing IDs of what they’re wearing, save it to the datastores and retrieve it later for whatever we need, ex loading clothing. So the string we’re looking to save might look something like this: “ShritID: 1234 | PantsID: 3445” Then we just use String Manipulation to get the Shrit and PantsID and re-apply that to the player.

If you need a visual example of what I’m talking about here you go:


This is on a game I’m working on atm, Players are able to cut parts, but I do all their cutting on the client side so I need to pass the info to the server some how so I can save their cuts once they’re done, So I’ve taken the Model Name, the part sizes inside the part, and the part name and put it into a string and send it over to the server. (Not sure if there is a better way to do this or not, this is just what works for me.)

Edit: I just realized how many "So"s their is in this…

2 Likes

i want to save hats / clothes / hair and color but no size :stuck_out_tongue: i dont really understand how u save the id tbh can u choose what it is or?

Well The ID for the clothes would be pulled from the player model. (You can’t just randomly make up a clothing ID number)
Example:

   local PantsID = game.Players.Bob.Character.Pants.PantsTemplate -- You'd want to make sure that game.Players.Bob.Character exists before doing this.

As for hats, that’s a bit more complicated to save.

oh i see would i save this id the same way i save values?

Yeah. I did a inventory system a while ago, and that was complicated, Some stuff you can’t just save as a whole string, so in some cases you’d be better off with individual values saving
So in the datastores you’d create a value for PantsID and set it for whatever the PantsTemplate was. and keep repeating for each item such as a hat, shirt, player color, etc…

Edit (In this case you’d be better off with individual values for each thing you’re saving in the player, kinda correcting myself here because I’m still working on the new inventory system I’m makin (just hit me suddenly), Each model I collect info about parts inside it and save it as a string, not just one huge Line of string with everything in the inventory that i wanted to save.)

could u make a example for this ? bcs a lot of people told me this but i dont really know how u would do this local pantsid = “12345”…game.Players.Bob.Character.Pants.PantsTemplate ???

2 Likes

Sure thing give me a few minutes.

Fifty Characters SMH

And so why aren’t we using a HumanoidDescription? Kinda curious why that hasn’t been brought up.

2 Likes

Didn’t know that was a thing till now, am I behind the times?

Ha, No… it’s fairly new and not prominent so, you get a pass.

But one of those should make storing a character a lot easier. If for some reason you didn’t want to use the users Id. This use case for the OP might be custom characters so this should work.

1 Like

Oooof…

Anyways an example of retrieving the Data would look like this:

if plr.Character ~= nil then -- plr = player in this case. We're just making sure the Character exists
   local PantsId = plr.Character.Pants.PantsTemplate -- grab the Pants the player is wearing
   local ShritID = plr.Character.Shirt.ShirtTemplate -- grab the Shirt the player is wearing
  -- Insert method to store PantsID and ShirtID to datastores somewhere around here
end 

if @T0ny knows how to work the HumanoidDescription he might be able to provide a better solution/example than what I’ve put.

PS: It’s going to take me some time to learn the HumanoidDescription otherwise I most likely would of gave you a different example. Thanks @T0ny for making me aware of something new :slight_smile:

Edit:

1 Like

This would be a better link to go to.

Also note that the Humanoid Description works like a regular object as well. You can freely get and set the values, so your code is pretty much good above. Just get the ID’s directly from the HumanoidDescription which can be attained from the Players Service.

1 Like

HumanoidDescriptions won’t do anything to make saving easier. You’re fine without them.

You need to serialize everything the player’s wearing. I give all my stuff unique IDs in-game, then save a string with all the IDs a player is wearing. E.g:

"A1|B2|C3|" --What my strings look like when I'm serializing stuff.

I then retrieve the items they’re wearing with something like this:

local id = "A1"
if string.find(data, id) then --Very simple trick to see if the player has an ID.
  --Clone the item with the corresponding ID to the player's character.
end

And that’s pretty much it. I know wrapping your head around data stores is really hard, and on top of that, you need knowledge of string manipulation, so I understand if you don’t get this. I’d be happy to explain further.

Also check these wiki pages out:

5 Likes

so
local id = “A1”
if string.find(data,id) then
game.replicatedstorage.hair:clone()
end ??? this sounds fairly simple is it supposed to be?

Almost like that. It is really simple. I personally store a StringValue in my items and then loop through all the items when a player joins. If its ID value is in the player’s “Equipped” data when their character loads, I clone it into their character.