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 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âŚ
i want to save hats / clothes / hair and color but no size 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 ???
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.
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.
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
Edit:
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.
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:
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.