Trying to insert a value into table without removing other saved values

Can’t insert a value into Inventory without removing the other values


	local WeaponDictionary = {
		["Sword"] = {
			Tradeable = true,
			Sellable = true,
			Equipped = false,
			Damage = 0,
			
			WeaponType = "Sword",
			
			Upgrades = {
				DamageUpgrade = {
					CostToUpgrade = 1000,
					UpgradeLevel = 1
				}
			},
		},
	}


Data["Inventory"]["Weapons"] = WeaponDictionary

I’m trying to insert a value in Weapons, but lets say you have other values already stored within it, I wouldn’t want it getting deleted due to using that

im new to scripting myself but cant you just use

table.insert(WeaponDictionary , yourvalue)
1 Like

I can, thing is, I’m trying to make the Index the Name of the sword

this might help you? im not really that knowledgeable in scripting, sorry.

I think that this:

Data["Inventory"]["Weapons"] = WeaponDictionary

is completely replacing what existed in Data["Inventory"]["Weapons"].
If you wanted to add to that, and you knew the index of the item to add, then you could add Sword by doing:

local newWeapon = "Sword"
Data["Inventory"]["Weapons"][newWeapon] = WeaponDictionary[newWeapon]
``
local Weapons = {"Sword", "Pickaxe"} --// Make weapons a table;
Data["Inventory"]["Weapons"].insert(WeaponDictionary)

Make the Weapons key point/refer to a table value & append new values to that table when necessary, as to not override any existing values within the table.

You could just get how many values are in the table, lets say 3 and do table.insert(table, value, 3 + 1)

1 Like