Module Data Difficulties

sorry about the repost, on my last post i had thought i figured out the solution but it didnt end up working as i had hoped

Currently my situation is that i have my own data script and data module, but when i add something to the data module it doesnt update the player’s module, i am looking for any solutions that can work and not models to use as id like to know what im working with

im not sure what exactly it is that is causing this problem, as i am cloning the module script and then add the data on top i dont know why its deleting the values it does not have data to

i have tried putting in the values before the data but that straight up didnt do anything, ive tried checking if it is nil, ive tried looping through and changing the player’s data before applying the data and it feels like nothing will work

ive had success with making it so that the new variables do get added onto the module script, but every time it ended up also resetting the rest of the data each time or causing it not to load/save so i had to delete that part completely

again i am looking for any ideas for what could work on my script and not models to use

the 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",
	},
		["Sword"] = {
			["Name"] = "Sword",
			["Object"] = "Secondary",
			["Damage"] = 5,
			["MAXXP"] = 100,
			["Element"] = "None",
			["Rarity"] = "Common",
			["Modifier"] = "None",
			["Quantity"] = 1,
			["Level"] = 0,
			["XP"] = 0,
			["Image"] =  "rbxassetid://11794015608";
			
	},
			["Knight"] = {
			["Name"] = "Knight",
			["Object"] = "Armour",
			["HP"] = 100,
			["MAXXP"] = 100,
			["Rarity"] = "Common",
			["Modifier"] = "None",
			["Quantity"] = 1,
			["Level"] = 0,
			["XP"] = 0,
			["Image"] =  "rbxassetid://11640624381";
			
	},
			["Tulip"] = {
			["Name"] = "Tulip",
			["Object"] = "Emerald",
			["Element"] = "None",
			["Rarity"] = "Emerald",
			["Modifier"] = "None",
			["Quantity"] = 1,
			["Image"] =  "rbxassetid://10897076168";
			
	},
		["BrightBurn"] = {
			["Name"] = "BrightBurn",
			["Object"] = "Ruby",
			["Element"] = "None",
			["Rarity"] = "Ruby",
			["Modifier"] = "None",
			["Quantity"] = 1,
			["Image"] =  "rbxassetid://10325574581";
			
		},
	["MoonStone"] = {
		["Name"] = "MoonStone",
		["Object"] = "Diamond",
		["Element"] = "None",
		["Rarity"] = "Diamond",
		["Modifier"] = "None",
		["Quantity"] = 1,
		["Image"] =  "rbxassetid://10325602328";
	
	},
}









return Weapons



local DataStore = game:GetService("DataStoreService")
local Store = DataStore:GetDataStore("DataStoreTests2")

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)
	local PlayerId = "Player_"..player.UserId

	local player_stats
	local success, errormessage = pcall(function()
		player_stats = Store:GetAsync(PlayerId)
	end)
	
	
	



	
	if player_stats and success then

----------- this solution is what i had tried before. but it caused the all data to return to default instead of just the data missing from the module

for c, p in pairs(datamodule) do
			if player_stats[c] == nil then
				player_stats[p] = datamodule[p]
			end
			for a, l in pairs(p) do
				if player_stats[a] == nil then
					player_stats[l] = datamodule[l]
				end
			end
		end


-------------------


		for i,v in pairs(datamodule) do
			
			for _,r in pairs(v) do
			
				if modulea[r] then
					modulea[r] = player_stats[r]
				else
					modulea[r] = datamodule[r]
				end
				
			end
		end
	else
		modulea = datamodule
	end
	
	
	
	
end)





game:GetService("Players").PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	
	local module = require(player:WaitForChild("PlayerData"))
	local success, errormessage = pcall(function()
		Store:SetAsync(playerUserId, module)
	end)


end)




for some reason the .rbxmx file isnt showing up as a studio file, and i am unable to open it up to look at the scripts inside for this to see what they did for saving

It’s a model, not a game file.

is that like the only option? ive yet to find a single devforum post or anything scripting based that could help with this problem without using another model which i want to avoid, id rather be able to use the script i created since i know what it does

I would rather just send you Datastore2 or the ProfileService module than trying to read code, if I know this is a Datastore issue. Datastore2 saves data in most efficient way possible, so you don’t need to worry about data loss, duplication glitches, and roblox servers failing.

this seems good but it doesnt really seem like its meant to be used with other module scripts

Still do need help by the way, datastore2 was not compatible enough for what i was going for
exactly as i explained, but ig u need to try to actually read the code to know

I believe I used to have the same problem since I do my own datastore methods as well, it’s similar to how you have yours done.

local function CheckContents(main_data, reference_data)
	local Type = typeof(reference_data)
		
	-- // if main data does not exist make reference data the new main
	if not (main_data) then
		return Settings:GetDeepCopy(reference_data)
	end
		
	-- // Reference isn't a table value
	if (Type ~= "table") then
		return main_data
	end
		
	-- // if by any means, the two provided datas are not the same, but main has a key 
	-- // Leave this up to verify integrity & verification processes
	if typeof(main_data) ~= Type then
		return main_data
	end
		
	-- // search through the reference data table to find missing keys
	for index, value in pairs(reference_data) do
		main_data[index] = CheckContents(main_data[index], value)
	end
		
	return main_data
end
CheckContents(data, newInfo.PlayerData)

Essentially it just compares the two and if the main data (the players data) doesn’t have a key that the referenced data has, it’ll create a new deep copied version of the data. And any abnormalities such as newly updated keys, like table[ThisKey] = 1 gets changed to table[ThisKey] = {} will be left for verification so the players old data doesn’t get removed.

This may or may not be what you’re looking for but this sort of works for me at the moment.