I have a working module data-store system, but when i add new values to the module script already existing data doesnt get updated with those values and i cant reset the data store every time i add a new item
I want it to be able to somehow add any missing values from the original module to the player’s data module, so if i add another weapon it wont be complete gone from the players data so i can tell through the Quantity value instead
ive tried looking up some solutions but i havent been able to find any that work for me
these are the scripts and if you have any questions feel free to ask
Server Script
local DataStore = game:GetService("DataStoreService")
local Store = DataStore:GetDataStore("DataStoreTesting")
local datamodule = require(game.ServerScriptService.DataModule)
game.Players.PlayerAdded:Connect(function(player)
local moduler = game.ServerScriptService.DataModule:Clone()
moduler.Parent = player
moduler.Name = "PlayerData"
local modulea = require(moduler)
wait(2)
local PlayerId = "Player_"..player.UserId
local player_stats
local success, errormessage = pcall(function()
player_stats = Store:GetAsync(PlayerId)
end)
if player_stats and success and modulea then
for i,v in pairs(modulea) do
if v then
modulea[v] = player_stats[v]
for _,r in pairs(v) do
modulea[r] = player_stats[r]
end
else
modulea[v] = datamodule[v]
for _,r in pairs(v) do
modulea[r] = datamodule[r]
end
end
end
else
modulea = datamodule
end
end)
local function create_table(player)
end
game:GetService("Players").PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local player_stats = create_table(player)
local module = require(player:WaitForChild("PlayerData"))
local success, errormessage = pcall(function()
Store:SetAsync(playerUserId, module)
end)
end)
Module Script
local Weapons = {
["Bow"] = {
["Name"] = "Bow",
["Object"] = "Primary",
["Damage"] = 10,
["MAXXP"] = 100,
["Element"] = "None",
["Rarity"] = "Common",
["Modifier"] = "None",
["Quantity"] = 1,
["Level"] = 0,
["XP"] = 0,
["Image"] = "rbxassetid://11786233351";
["Number"] = "0"
},
["Sword"] = {
["Name"] = "Sword",
["Object"] = "Secondary",
["Damage"] = 5,
["MAXXP"] = 100,
["Element"] = "None",
["Rarity"] = "Common",
["Modifier"] = "None",
["Quantity"] = 1,
["Level"] = 0,
["XP"] = 0,
["Image"] = "rbxassetid://11794015608";
["Number"] = "0"
},
["Knight"] = {
["Name"] = "Knight",
["Object"] = "Armour",
["HP"] = 100,
["MAXXP"] = 100,
["Rarity"] = "Common",
["Modifier"] = "None",
["Quantity"] = 1,
["Level"] = 0,
["XP"] = 0,
["Image"] = "rbxassetid://11640624381";
["Number"] = "0"
},
["Tulip"] = {
["Name"] = "Tulip",
["Object"] = "Emerald",
["Element"] = "None",
["Rarity"] = "Emerald",
["Modifier"] = "None",
["Quantity"] = 1,
["Image"] = "rbxassetid://10897076168";
["Number"] = "1"
},
["BrightBurn"] = {
["Name"] = "BrightBurn",
["Object"] = "Ruby",
["Element"] = "None",
["Rarity"] = "Ruby",
["Modifier"] = "None",
["Quantity"] = 1,
["Image"] = "rbxassetid://10325574581";
["Number"] = "1"
},
["MoonStone"] = {
["Name"] = "MoonStone",
["Object"] = "Diamond",
["Element"] = "None",
["Rarity"] = "Diamond",
["Modifier"] = "None",
["Quantity"] = 1,
["Image"] = "rbxassetid://10325602328";
["Number"] = "1"
},
}
return Weapons