Ui performance issues [HELP]

heya! I’m making an inventory system and my current system deletes everything and makes new frames for all items. this is not ideal for large inventories and was wondering if anyone could help me figure out how to make a better system than this? i am using profileservice to save and load the items.

1 Like

I’d recommend using a frame with a UIGridLayout object, which will automatically position the other frames for all the items. You can read more about the UIGridLayout at UIGridLayout | Documentation - Roblox Creator Hub.

If you need any further assistance, please don’t hesitate to let me know.

1 Like

I am referring to refreshing the inventory. Deleting and re-adding the UI each time the inventory refreshes is not ideal and can cause graphical problems. I am already using a grid layout.

1 Like

Oh. In that case, i’d recommend using ChildRemoved and ChildAdded to only refresh the UI when necessary (e.g. a new item being added)

You can do so through the following script:

    -- add refresh script here

    -- add refresh script here
1 Like

use ChildRemoved and ChildAdded

    --your code
1 Like

Have a table with all data and from there, add or remove, I would guess you already have one for the inventory so it’ll only need to be reshaped and some code edits, won’t be a big headache for you, hopefully. Here is some example code to make more sense.

This was written here and not in Roblox Studio, expect small mistakes.

type Data = {
	frame: GuiObject,
	item: Tool -- edit this to whatever type you have for it, or `any`.
type Inventory = {Data}

local inventory: Inventory = {}

-- adding item
local frame -- create the frame, edit properties, etc
table.insert(inventory, {
	frame = frame,
	item = item

-- removing item

-- if you have index then great if you have item or the frame, that will
-- require a loop to get the index, say you have it now
local index -- however you have it.

table.remove(inventory, index)
1 Like

it is loading a table, not instances.

Perhaps you could cycle through all the instances in the table?