How do i make a scrollable inventory?

here is what i did:

task.wait(1)

local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Backpack = Player.Backpack

local num = 0

local debounce = false
local scroll = 0
local toolTable = {}

for _, v in pairs(Backpack:GetChildren()) do
num += 1
toolTable[num] = v.Name
end

local function equip()
Player.Character.Humanoid:UnequipTools()
Player.Character.Humanoid:EquipTool(Backpack[toolTable[scroll]])
end

Mouse.WheelForward:Connect(function()
if debounce == false then
debounce = true
scroll -= 1
if scroll <= 1 then
scroll = 1
end
equip()
task.wait()
debounce = false
end
end)

Mouse.WheelBackward:Connect(function()
if debounce == false then
debounce = true
scroll += 1
local max = Player.Backpack:GetChildren()
if scroll <= #max + 1 then
scroll = #max + 1
end
equip()
task.wait()
debounce = false
end
end)

it dosent work at all

1 Like

In many cases you won’t need to implement this yourself. Check out ScrollingFrame and see if that fits your needs.

1 Like