You can't store Instances in DataStore
(unlike with Data Persistence
).
This is how I would do it, as long as each item of the same type had the same statistics. For example, all Iron Swords do the same amount of damage and have the same reload time. If this is the case, use the below method. If not, it is a lot more complex.
Give each individual item a number, or give each individual item a special string name, and save it in DataStore
. For example:
1 | local dataStore = game:GetService( "DataStoreService" ):GetDataStore( "Inventory" ) |
5 | game.OnClose = function () |
6 | local playerKey = "user_" .. player.UserId |
7 | datastore:SetAsync(playerKey, inventory) |
and when a player joins...
1 | local dataStore = game:GetService( "DataStoreService" ):GetDataStore( "Inventory" ) |
3 | game:GetService( "Players" ).PlayerAdded:connect( function () |
4 | local playerKey = "user_" .. player.UserId |
5 | inventory = datastore:GetAsync(playerKey) |