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)