In my game, I want there to be inventory saving. Say if the player bought clothes, it would save what clothes they have on, and load them back in when they rejoined. I don't know much about datastores, and my current attempts have failed. Does anyone know a bit more about datastores that could help me with this?
I personally would recommend that you store a string of all names in a table and save that, then when they hop on the game again, you iterate through that table and where you keep clothes. If there is a match, clone it to them and whatever you have to do to make them wear it. Hope that gets you in the right direction!
Use this code to get their inventory:
01 | game.Players.PlayerRemoving:Connect( function (player) |
02 | local char = player.Character |
03 |
04 | for i,v in pairs (player.Backpack:GetChildren()) do |
05 | table.insert(table,#table + 1 ,v) |
06 | end |
07 |
08 | for i,v in pairs (char:GetChildren()) do |
09 | if v:IsA( "Tool" ) then |
10 | table.insert(table,#table + 1 ,v) |
11 | break |
12 | end |
13 | end |
14 |
15 | --Data store code |
16 | end ) |
Then DataStore it all. Hope this helped!