Module Function Not Updating Player Data Table Properly?

I’ve got an issue with my datastore, so I’ll try my best to explain it.

Whenever the player joins the game, my custom datastore system sets a default key (which stores a table for them) in an identical format to this:

Example Player Data Table

module["PlayerData-"..tostring(Player.UserId)] = {
        ["SpleefCoins"] = 0,
        ["CRW"] = false,
        ["Wins"] = 0,
        ["Benefits"] = 1,
        ["Equipped"] = "1",
        ["EquippedEffect"] = "1",
        ["Level"] = "1",
        ["Rank"] = "Newbie",
        ["XP"] = 0,
        ["XP_Limit"] = 30
    }
    module["Inventory-"..tostring(Player.UserId)] = {
        ["Trails"] = {
            "1"
        },
        ["Effects"] = {
            "1"
        }
    }

I have a server script which actively communicates with the module by calling a scripted module function whenever one of the instanced values are changed. When this happens, the script passes along 3 arguments to the module function:

  1. The Player: To Get The Allocated Data Table
  2. The name of the value: To find the key that stores the current value on the module
  3. The New Value, So I can update the outdated value within the table

The function to update the data is this:

function module.UpdatePlayerData(Player, oldValueName, newValue)
	print("Recieved Request")
	local PlayerTable = module["PlayerData-"..tostring(Player.UserId)]
	for indexValue, Value in pairs(PlayerTable) do
		if indexValue == oldValueName then
			Value = newValue
			print("Set "..indexValue.." to "..tostring(newValue))
		end
	end
end

It prints it set the value, even though when the save function prints the old table anyway:

function module.SaveAllData()
	local PlayerUserId 
	local PlayerKey
	for indexPlayer, Player in pairs(game.Players:GetPlayers()) do
		PlayerUserId = Player.UserId
		PlayerKey = "Player-"..PlayerUserId
		local PlayerTable = module["PlayerData-"..tostring(PlayerUserId)]
		for i, v in pairs(PlayerTable) do 
			print("Index: "..i)
			print("Value: "..tostring(v))
		end
		local InventoryTable = module["Inventory-"..PlayerUserId]
		if PlayerTable then
			local success, errormessage = pcall(function()
				PlayerDatastore:SetAsync(PlayerKey, PlayerTable)
				BackupPlayerDatastore:SetAsync(PlayerKey, PlayerTable)	
				InventoryDatastore:SetAsync(PlayerKey, InventoryTable)
				BackupInventoryStore:SetAsync(PlayerKey, InventoryTable)
			end)
			if success then
				print("Saved "..Player.Name.."'s Data Successfully")
			else
				wait("Error: "..errormessage)
			end
		end
	end
end

I’ll be extremely greatful if there are fast responses. :grinning_face_with_smiling_eyes:

instead of spamming it try putting it in https://scriptinghelpers.org/ or somewhere else if no one can solve your answer try to search it up.

Oh sorry, I forgot to get rid of my other post. This was the updated one, with the issue better explained

Nevermind, I fixed it. Sorry for the reposting