hello! i have made a system where the values for weapons can be saved and shown in a ui scrolling frame. however im having a problem where if i was too add a new weapon into the table it would only show the preexisting weapons in the table and not the new one. i had a semi - fix where i could change the name of the data store so it would show all of them but thats just not practical. how would i make it so when a new weapon is added into the table it would show with the preexisting weapons?
local DataStoreService = game:GetService("DataStoreService")
local weaponDamageData = DataStoreService:GetDataStore("sdwr")
weaponModuleStats.weaponStats = {
["punch"] = {
damage = 5,
price = 0,
unlockAmount = 0,
description = "you punch people i guess. not much to be said",
image = "rbxassetid://17736469807",
requiredLevel = 0,
unlockable = false,
unlocked = true,
},
["bat"] = {
damage = 9,
price = 65,
unlockAmount = 0,
description = "an average baseball bat.",
image = "rbxassetid://9831327336",
requiredLevel = 0,
unlockable = true,
unlocked = true,
},
["BADbat"] = {
damage = 50,
price = 100,
unlockAmount = 250,
description = "a VERY bad BAT baseball bat.",
image = "rbxassetid://5134415522",
requiredLevel = 0,
unlockable = true,
unlocked = false,
},
["crowbar"] = {
damage = 11,
price = 150,
unlockAmount = 300,
description = "a crowbar that lowkey kinda old but very useful.",
image = "rbxassetid://4784609474",
requiredLevel = 5,
unlockable = true,
unlocked = false,
},
["light vest"] = {
protection = 15,
price = 250,
unlockAmount = 500,
description = "a vest that gives you +15 health.",
image = "rbxassetid://8303115917",
requiredLevel = 10,
unlockable = true,
unlocked = false,
},
}
function weaponModuleStats:saveWeaponStats(player, statsTable)
local success, errorMessage = pcall(function()
weaponDamageData:SetAsync(player.UserId .. "-weaponStats", statsTable)
end)
if not success then
warn("Failed to save weapon damage: " .. errorMessage)
end
end
function weaponModuleStats:loadWeaponStats(player)
local success, weaponStatsTable = pcall(function()
return weaponDamageData:GetAsync(player.UserId .. "-weaponStats")
end)
if success and weaponStatsTable then
return weaponStatsTable
else
if not success then
warn("Failed to load weapon damage: " .. weaponStatsTable)
end
return weaponModuleStats.weaponStats
end
end