Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ ========= CONFIG ========= ]]
- local DEBUG = false -- set true to print what's going on
- --[[ ========================== ]]
- local UserInputService = game:GetService("UserInputService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local playerModule = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
- local controls = playerModule:GetControls()
- local UI = script.Parent
- UI.Enabled = false
- local tabsContainer = UI.MainFrame.Tabs
- -- order/sanitize tabs so GetChildren() randomness won't break logic
- local function getOrderedTabs()
- local list = {}
- for _, child in ipairs(tabsContainer:GetChildren()) do
- if child:IsA("Frame") or child:IsA("ImageLabel") then
- table.insert(list, child)
- end
- end
- table.sort(list, function(a, b)
- return (a.LayoutOrder or 0) < (b.LayoutOrder or 0)
- end)
- return list
- end
- local tabs = getOrderedTabs()
- local selectedTabIndex = 1
- local selectedItemIndex = 1
- -- IMAGES --
- local image1 = UI.MainFrame.InfoBox.UpDown.image1
- local image2 = UI.MainFrame.InfoBox.UpDown.image2
- local image3 = UI.MainFrame.InfoBox.UpDown.image3
- local image4 = UI.MainFrame.InfoBox.UpDown.image4
- local image5 = UI.MainFrame.InfoBox.Use.image1
- local image6 = UI.MainFrame.InfoBox.Use.image2
- local image7 = UI.MainFrame.InfoBox.ChangeTab.image1
- local image8 = UI.MainFrame.InfoBox.ChangeTab.image2
- local image9 = UI.MainFrame.InfoBox.ChangeTab.image3
- local image10 = UI.MainFrame.InfoBox.ChangeTab.image4
- local image11 = UI.MainFrame.InfoBox.Back.image1
- local image12 = UI.MainFrame.InfoBox.Back.image2
- local pc_images = {image1, image3, image5, image7, image9, image11}
- local console_images = {image2, image4, image6, image8, image10, image12}
- if UserInputService.GamepadEnabled then
- for _, img in ipairs(console_images) do img.Visible = true end
- for _, img in ipairs(pc_images) do img.Visible = false end
- else
- for _, img in ipairs(console_images) do img.Visible = false end
- for _, img in ipairs(pc_images) do img.Visible = true end
- end
- -- ========== PlayerStorage handling (robust) ==========
- local playerStorage
- local childAddedConn, childRemovedConn
- local function disconnectStorageSignals()
- if childAddedConn then childAddedConn:Disconnect() end
- if childRemovedConn then childRemovedConn:Disconnect() end
- childAddedConn, childRemovedConn = nil, nil
- end
- local function onStorageChildAdded(child)
- if DEBUG then print("[Inventory] Item added:", child.Name, child.ClassName) end
- updatePlayerItems()
- end
- local function onStorageChildRemoved(child)
- if DEBUG then print("[Inventory] Item removed:", child.Name, child.ClassName) end
- updatePlayerItems()
- end
- local function hookPlayerStorage(storage)
- if DEBUG then print("[Inventory] Hooking PlayerStorage:", storage) end
- disconnectStorageSignals()
- playerStorage = storage
- childAddedConn = playerStorage.ChildAdded:Connect(onStorageChildAdded)
- childRemovedConn = playerStorage.ChildRemoved:Connect(onStorageChildRemoved)
- updatePlayerItems()
- end
- -- wait / (re)hook PlayerStorage even if it's created later
- local function findOrWaitForPlayerStorage()
- local storage = player:FindFirstChild("PlayerStorage")
- if storage then
- hookPlayerStorage(storage)
- else
- if DEBUG then print("[Inventory] Waiting for PlayerStorage...") end
- storage = player:WaitForChild("PlayerStorage")
- hookPlayerStorage(storage)
- end
- end
- -- also handle the case where PlayerStorage might get recreated (rare but safe to cover)
- player.ChildAdded:Connect(function(child)
- if child.Name == "PlayerStorage" then
- hookPlayerStorage(child)
- end
- end)
- -- ========== UI helpers ==========
- local function getItemsFolderForTab(tab)
- -- If your ItemsFolder is *inside* the tab, keep this.
- -- If it's elsewhere, change this to the correct path.
- return tab:FindFirstChild("ItemsFolder")
- end
- local function getItemsForCurrentTab()
- if selectedTabIndex ~= 1 then
- return {}
- end
- local currentTab = tabs[selectedTabIndex]
- local itemsFolder = getItemsFolderForTab(currentTab)
- local items = {}
- if itemsFolder then
- for _, child in ipairs(itemsFolder:GetChildren()) do
- if child:IsA("TextLabel") then
- table.insert(items, child)
- end
- end
- end
- return items
- end
- local function highlightTabs()
- for i, tab in ipairs(tabs) do
- if tab:IsA("Frame") or tab:IsA("ImageLabel") then
- if i == selectedTabIndex then
- tab.BackgroundTransparency = 0
- tab.BackgroundColor3 = Color3.fromRGB(45, 45, 45) -- Selected
- else
- tab.BackgroundTransparency = 1
- end
- end
- end
- end
- function highlightItems()
- local items = getItemsForCurrentTab()
- for i, item in ipairs(items) do
- if i == selectedItemIndex then
- item.TextColor3 = Color3.fromRGB(255, 255, 255)
- else
- item.TextColor3 = Color3.fromRGB(200, 200, 200)
- end
- end
- end
- -- Populate the list from PlayerStorage
- function updatePlayerItems()
- if not tabs[1] then return end
- local itemsFolder = getItemsFolderForTab(tabs[1])
- if not itemsFolder then
- if DEBUG then warn("[Inventory] ItemsFolder not found under first tab!") end
- return
- end
- -- optional: add a UIListLayout if you want auto layout
- if not itemsFolder:FindFirstChildOfClass("UIListLayout") then
- local layout = Instance.new("UIListLayout")
- layout.Padding = UDim.new(0, 2)
- layout.FillDirection = Enum.FillDirection.Vertical
- layout.SortOrder = Enum.SortOrder.LayoutOrder
- layout.Parent = itemsFolder
- end
- -- Clear old labels
- for _, child in ipairs(itemsFolder:GetChildren()) do
- if child:IsA("TextLabel") then
- child:Destroy()
- end
- end
- if not playerStorage then
- if DEBUG then warn("[Inventory] playerStorage is nil at update time") end
- return
- end
- -- Create labels for each Part or Model in playerStorage
- for _, item in ipairs(playerStorage:GetChildren()) do
- if item:IsA("Model") or item:IsA("Part") then
- local newLabel = Instance.new("TextLabel")
- newLabel.Size = UDim2.new(1, 0, 0, 24)
- newLabel.BackgroundTransparency = 1
- newLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
- newLabel.Font = Enum.Font.SourceSans
- newLabel.TextScaled = false
- newLabel.TextXAlignment = Enum.TextXAlignment.Left
- newLabel.Text = "- " .. item.Name
- newLabel.Parent = itemsFolder
- newLabel.Position = UDim2.new(0.821, 0,2.233, 0)
- end
- end
- selectedItemIndex = 1
- highlightItems()
- end
- -- ========== Open / Close menu ==========
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.ButtonX then
- controls:Disable()
- UI.Enabled = true
- selectedTabIndex = 1
- selectedItemIndex = 1
- -- Re-get/rehook player storage if for some reason it's not there yet
- if not playerStorage then
- findOrWaitForPlayerStorage()
- else
- updatePlayerItems()
- end
- highlightTabs()
- highlightItems()
- end
- end)
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.Escape or input.KeyCode == Enum.KeyCode.ButtonY then
- controls:Enable()
- UI.Enabled = false
- selectedTabIndex = 1
- selectedItemIndex = 1
- highlightTabs()
- highlightItems()
- end
- end)
- -- ========== Navigation ==========
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- -- NEXT TAB (E / DPadRight)
- if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.DPadRight then
- selectedTabIndex += 1
- if selectedTabIndex > #tabs then
- selectedTabIndex = 1
- end
- selectedItemIndex = 1
- highlightTabs()
- highlightItems()
- -- PREVIOUS TAB (Q / DPadLeft)
- elseif input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.DPadLeft then
- selectedTabIndex -= 1
- if selectedTabIndex < 1 then
- selectedTabIndex = #tabs
- end
- selectedItemIndex = 1
- highlightTabs()
- highlightItems()
- -- UP (Up / DPadUp)
- elseif input.KeyCode == Enum.KeyCode.Up or input.KeyCode == Enum.KeyCode.DPadUp then
- local items = getItemsForCurrentTab()
- if #items > 0 then
- selectedItemIndex -= 1
- if selectedItemIndex < 1 then
- selectedItemIndex = #items
- end
- highlightItems()
- end
- -- DOWN (Down / DPadDown)
- elseif input.KeyCode == Enum.KeyCode.Down or input.KeyCode == Enum.KeyCode.DPadDown then
- local items = getItemsForCurrentTab()
- if #items > 0 then
- selectedItemIndex += 1
- if selectedItemIndex > #items then
- selectedItemIndex = 1
- end
- highlightItems()
- end
- end
- end)
- -- Initial setup
- highlightTabs()
- highlightItems()
- findOrWaitForPlayerStorage()
Advertisement
Add Comment
Please, Sign In to add comment