Okay, I finally found a solution.
I don’t know why it works, but it does.
If anyone else has the same problem or wants to do something similar, the item is already assigned to a player when it spawns, and then I check whether the player is the one to whom the item was assigned. If so, the item is visible to the respective player when it spawns; if not, it is hidden.
Maybe someone can explain to me why it works like this and not how I had it before?