Strange issue regarding items in a table

Hello.

I have made a modular inventory system for my game, but I’ve come across a slight issue.

When I save all the powers a player has, I only save the ones they have, and not the ones they need.
I then set up a structure for their data in their inventory module, which is set to them only having the default power, no power equipped, and they still need every other power in the game.

I then give the function the player’s data to unpack. For one power (Double jump), this power is not contained in the owned powers sector of player data, but once the iteration has completed, it is not within the owned powers or needed powers sector of the player’s data.

My use of self here references the module, not to be confused with an object as this module is not Object-Oriented

Here’s a snippet the Init function:

function inventory:Init(playerData:PlayerData) --unpack player data
	--powers
	local powersSector = self.Items.Powers
	for _, ownedPower in next, playerData.OwnedPowers, nil do
		table.insert(powersSector.OwnedPowers, ownedPower)
		table.remove(powersSector.NeededPowers, table.find(powersSector.NeededPowers, ownedPower))
	end

    --other data gets unpacked here but does not affect that table
end

I added print statements for each power, making it print out the current power getting removed (before it was removed) and it outputs nil each time.

Any help is appreciated, I’m confused where I went wrong.

I’ve created a workaround manually, but if anyone knows why this might be happening and how to fix it without a workaround please let me know, if it’s a bug that I created I would like to fix it.