🏠

VirtualScroller Module Documentation

Version: 1.0.0 | Author: @richmensch | Released: October 12, 2025


Introduction

The VirtualScroller is a Roblox Lua module designed for efficient scrolling through large datasets in a UI ScrollingFrame. It uses virtualization to only render items that are currently visible (plus a buffer), reducing performance overhead. Ideal for lists, grids, or inventories with thousands of items.

Key features:

Info: Pool size is capped at 500 for performance.

Installation

Recommended

To install, insert the module script into your Roblox project (e.g., in ReplicatedStorage) and require it in your scripts.

  1. Get the ModuleScript Model from Roblox.
  2. Place it in an appropriate location, like ReplicatedStorage.
  3. In your script: local VirtualScroller = require(ReplicatedStorage.VirtualScroller)
  4. Use in any localscript.
Warning: Ensure the ScrollingFrame and ItemTemplate are set up in your UI before initializing.

Usage

Create a new instance with required parameters. Example:

local VirtualScroller = require(ReplicatedStorage.VirtualScroller)

-- Setup
local scrollingFrame = script.Parent.ScrollingFrame
local itemTemplate = scrollingFrame.ItemTemplate
local data = {}  -- e.g., {{Name = "Item1"}, {Name = "Item2"}}

local scroller = VirtualScroller.new(
    scrollingFrame,
    itemTemplate,
    data,
    50,  -- itemHeight
    2,   -- numColumns
    0.5, -- itemWidthScale
    15,  -- bufferRows
    function(frame, data, index)
        frame.NameLabel.Text = data.Name or "Item " .. index
    end
)

The scroller handles rendering and updates automatically.

Important: Set itemTemplate.Visible = false initially.

Constructor: VirtualScroller.new()

Creates a new instance. Parameters after dataTable are optional.

Returns the instance.


Methods

GetVisibleItemCount()

Returns visible items count.

local count = scroller:GetVisibleItemCount()

ReloadData(newDataTable)

Reloads full data and updates view. (Useful for Inventory Page Changes without multiple ScrollingFrames.)

scroller:ReloadData(newData)

ScrollToIndex(index, animated)

Scrolls to index, optionally animated.

scroller:ScrollToIndex(10, true)

SortData(comparatorFunction)

Sorts data and updates the Scrollingframe.

scroller:SortData(function(a, b) return a.Name < b.Name end)

AddItem(dataItem, position)

Adds item.

scroller:AddItem({Name = "New Item", Id = "?"})

RemoveItem(index)

Removes item at index.

scroller:RemoveItem(3)

Destroy()

Cleans up resources.

scroller:Destroy()

Notes