How to save different informations of a saved object?

Hey guys!

I’m trying to make a game using Dungeon Quest mechanics because I love Dungeon Quest.

And I’m wondering on How to save the weapons for exemple, or the armors.

Let me explain:

When you have a sword for exemple, it as a custom Spell Power, or a custom Physical Power.

Like your weapon as: 107 Spell Power, 1856 Physical Power and 354 Max Upgrades.

I know how to save objects in the inventory using Arrays, but when I save my item, how do I associate the stats of the weapon into the save?

Like each object in my savedTable need to have the information like “ObjectName, Spell Power, Physical Power, MaxUpgrades, Upgrades Done”…

I don’t know if I’m clear, ask me questions for more informations!

Thx you for your help!

I think you can use module scripts?

Mhh, I’m not sure to see what are you talking about.

I know what is a module script but I don’t understand how can I do this with a moduleScript?

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

I’ll try this later on and give you the feedback if it works or not. Thx you for the support!

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.

1 Like

Can you send me your game link pls?

I’m would like to try it if it is possible !

Thanks for your help !

1 Like

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.

The grid is so cool!
I like the GUIs, your game is very cool!

Do you think you can show me the grid system to place items? It so intristing !!!

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.

1 Like

thx you very much ! :smiley:
Bye