how to make scroll frame auto scroll roblox

-- Step 1: Create a ScreenGui and Frame for UI elements
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "AutoScrollFrameGui"
screenGui.Parent = playerGui

local frame = Instance.new("Frame")
frame.Name = "AutoScrollFrame"
frame.Size = UDim2.new(0, 200, 0, 300)
frame.Position = UDim2.new(0.5, -100, 0.5, -150)
frame.BackgroundTransparency = 0.5
frame.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
frame.Parent = screenGui

-- Step 2: Create a ScrollFrame and set properties
local scrollFrame = Instance.new("ScrollingFrame")
scrollFrame.Name = "AutoScrollingFrame"
scrollFrame.Size = UDim2.new(1, 0, 1, 0)
scrollFrame.CanvasSize = UDim2.new(0, 0, 5, 0) -- Adjust the CanvasSize as needed
scrollFrame.Parent = frame

-- Step 3: Create UI elements to be placed inside the ScrollFrame
for i = 1, 10 do
    local label = Instance.new("TextLabel")
    label.Name = "Item" .. i
    label.Size = UDim2.new(1, 0, 0, 30)
    label.Position = UDim2.new(0, 0, 0, (i - 1) * 30)
    label.BackgroundTransparency = 0.5
    label.BackgroundColor3 = Color3.new(0.7, 0.7, 0.7)
    label.Text = "Item " .. i
    label.Parent = scrollFrame
end

-- Step 4: Function to auto-scroll the ScrollFrame
local function autoScroll()
    local maxHeight = scrollFrame.CanvasSize.Y.Offset - scrollFrame.Size.Y.Offset
    while wait(1) do
        scrollFrame.CanvasPosition = Vector2.new(0, math.random(0, maxHeight))
    end
end

-- Step 5: Start auto-scrolling in a separate thread
spawn(autoScroll)