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)

2 comments
and how exactly i do this? i want make a script that save the object that is touching a part, and when enter, he will load this object again, how i do this?
and how exactly i do this? i want make a script that save the object that is touching a part, and when enter, he will load this object again, how i do this?