I know the basics of Datastores but i do not know how to save objects...This script is suppose to make a folder in the player, and if there are any Tools/Bricks/Models/etc...inside of that folder then insert them into a table and save them to the datastore. It does not work though so what i can i do to store and load them?
local DataStore = game:GetService("DataStoreService"):GetDataStore("BackPack") game.Players.PlayerAdded:connect(function(player) local Storage = Instance.new("Folder",player) Storage.Name = "Storage" --Name of folder local key = "user-" .. player.userId --Key local storeditems = DataStore:GetAsync(key) if storeditems then storeditems.Parent = Storage else local items = {} --Items table local get = Storage:GetChildren()-- get items for i, v in pairs(get) do --save tools table.insert(key, v) DataStore:SetAsync(key, items) end end end) game.Players.PlayerRemoving:connect(function(player) local items = {} local key = "user-" .. player.userId for i, v in pairs(get) do --Save tools table.insert(key, v) DataStore:SetAsync(key, items) end end)
You can't store Instances. Roblox doesn't serialize them, because JSON has no support for them, and Roblox doesn't support binary data structures for storage (Truth - Roblox actually doesn't like a lot of binary values).
The solution?
Store the information which describes the Instance. Is it an IntValue? Store the number. Part? Store the information to make it, such as the name of the thing you cloned it from. Weapon? Store the name. Serialization is an important part of storage which was missed out from DataStores for some unknown reason.