I’m creating a system to save and load a player’s weapons. It also needs to save stats about a weapon. Currently, I’m very, very close to a successful system, HOWEVER, I just can’t get the last little it to work.
LOADING:
for i, v in pairs(WeaponsToLoad) do
if v[1] ~= "Basic Sword" then
local Weapon = game.ServerStorage.Weapons:FindFirstChild(v[1])
if Weapon ~= nil then
local personalWep = Weapon:Clone()
personalWep.Parent = p.Inventory.Weapons
personalWep.weaponStats.BaseDamage.Value = v[2]
personalWep.weaponStats.Level.Value = v[3]
personalWep.weaponStats.Rarity.Value = v[4]
personalWep.weaponStats.WeaponValue.Value = v[5]
end
end
end
SAVING:
for i, v in pairs(p.Inventory.Weapons:GetChildren()) do
local subTable = {}
subTable[1] = v.Name
subTable[2] = v.weaponStats.BaseDamage.Value
subTable[3] = v.weaponStats.Level.Value
subTable[4] = v.weaponStats.Rarity.Value
subTable[5] = v.weaponStats.WeaponValue.Value
table.insert(WeaponTable, i, subTable)
end
WHAT IS DRIVING ME INSANE:
When loading data, it can find the name of the weapon from the table and successfully load it into the player’s inventory. I’ve printed the length of the loaded table, and it’s 5, like it should be. I’ve printed the values it is saving, and they’ve all been accurate. BUT WHEN ACTUALLY LOADING VALUES, such as v[3], it loads back to the default value.
FOR INSTANCE:
I save a weapon called “Mace”. I upgrade its level from 1 to 15 during gameplay. When loading back in, it reverts to 1. BUT the weapon still loads into inventory, meaning it’s just v[2]-v[5] that aren’t loading, and I cannot for the life of me, figure out why.