Inventory Reloading deletes all items except the newest one

Hi, im making an inventory system which stores its data in a folder and reloads the data from it every time a new item is collected, however, the frame is distorted and the other items dont show except the newest one
script

local items = require(game.ReplicatedStorage.Items)
local template = game.ReplicatedStorage.Template:Clone()

game.Players.PlayerAdded:Connect(function(plr)

local plr_inventory = Instance.new("Folder", game.ReplicatedStorage)
plr_inventory.Name = plr.Name

local temp = game.ReplicatedStorage.Template
	
game.ReplicatedStorage.Cases.BuyCase.OnServerEvent:Connect(function(player, unboxed)
	local item = Instance.new("Folder", plr_inventory)
		item.Name = items.Items[unboxed].name
	local image = Instance.new("ImageLabel", item)
		image.Image = "rbxassetid://"..items.Items[unboxed].imageID
	local price = Instance.new("NumberValue", item)
		price.Value = items.Items[unboxed].price
			
	
		player.PlayerGui.ScreenGui.background.inventory:ClearAllChildren()
			task.wait(0.1)
				
				for i, v in pairs(game.ReplicatedStorage:FindFirstChild(player.Name):GetChildren()) do
					local tempclone = temp:Clone()
					tempclone.Parent = player.PlayerGui.ScreenGui.background.inventory
					tempclone.Name = v.Name
					tempclone.ImageLabel.Image =  v.ImageLabel.Image
					end
		
	
end)
end)

1 Like

have you checked what’s inside the inventory folder in ReplicatedStorage?

2 Likes

also, did the inventory frame include a UIListLayout? that may be the reason why it bugs out, you’ll want to use a for loop and make sure you’re not clearing out any listlayouts, rather than using ClearAllChildren()

2 Likes

yup, everything is there, i just use folders which contain the data of each item

1 Like

you forgot to add a grid layout. the old ones are covered by the new one

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.