I think I just found the solution of my own problem:
local DS = game:GetService("DataStoreService"):GetDataStore("DataStore1")
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(plr)
local ArmorsSave = {}
for _, v in pairs(plr.Inventory.Armors:GetChildren()) do
local array = {
name = v.Name,
spellPower = v.SpellPower,
physicalPower = v.PhysicalPower,
stamina = v.Stamina,
rarity = v.Rarity,
maxUpgrades = v.MaxUpgrades,
Upgrades = v.Upgrades,
--... You can add more informations related to the object here
}
table.insert(armorsSave, array)
end
local success, err = pcall(function()
DS:SetAsync("Armors-"..plr.UserId, armorsSave)
end)
end
Here’s what I use in my sandbox tycoon script, hopefully, it can help.
local function Save(plr)
local key = "plr-"..plr.UserId
local save = {}
for i, obj in pairs(plot.PlacedItems:GetChildren()) do
if obj then
table.insert(save, {
["Name"] = obj.Name,
["CFS"] = {
["X"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).X;
["Y"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Y;
["Z"] = plot.Plot.CFrame:ToObjectSpace(CFrame.new(obj.PrimaryPart.CFrame.p)).Z;
["R"] = obj.PrimaryPart.Orientation.Y
},
["Level"] = obj.LevelProperties.Level.Value,
["ItemId"] = obj.LevelProperties.ItemId.Value
})
end
end
local success, err = pcall(function()
DataStore:SetAsync(key, save)
end)
if not success then
warn("Failed to over-write data( "..tostring(err))
end
end
You can use something similar like tables to save info. I also recommend using function Save(plr) format and just calling it whenever player leaves. it won’t make any difference but it will help you keep scripts organized.
The game is just a testing place i just test new stuff in it so many stuff maybe totally incomplete.
If you just wanna check the object datastore then sure.
I have modified a version of the placement system from youtube. If you wanna check out the base code of it then this might help. It’s not very customisable but I have tried to tweak some stuff in my own version to make it the way I like. It will help you understand some basics of it.