I am making an Inventory system in my game and found some issues. I have a server side inventory table, which when updated, fires a remote event to player, which updates the inventory GUI. But when I add 2 items at the same time, all the items in the Inventory GUI are duplicated.
On update inventory event, the client deletes all item frames in the inventory GUI, then creates new ones for the changed inventory table.
-- Add an item to inventory.
UpdateInventoryEvent:FireClient(player, inventory)
-- Add some more items to inventory.
UpdateInventoryEvent:FireClient(player, inventory)
If I try to update inventory twice in a row with no delay, item frames in the inventory GUI are duplicated. First event is simply too slow to create new item frames, therefore the second event does not delete the item frames which the first event created, because they are still being created. How do I fix this problem?