I want to store purchased inventory somewhere in the cloud (DataStore.) How do I do so?
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:
local dataStore = game:GetService("DataStoreService"):GetDataStore("Inventory") local inventory = --create table of Inventory items by their unique number/string game.OnClose = function() local playerKey = "user_" .. player.UserId --assuming player is defined datastore:SetAsync(playerKey, inventory) end
and when a player joins...
local dataStore = game:GetService("DataStoreService"):GetDataStore("Inventory") game:GetService("Players").PlayerAdded:connect(function() local playerKey = "user_" .. player.UserId inventory = datastore:GetAsync(playerKey) end)