Guest User

Untitled

a guest
Jul 27th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. --[[ ========= CONFIG ========= ]]
  2. local DEBUG = false -- set true to print what's going on
  3. --[[ ========================== ]]
  4.  
  5. local UserInputService = game:GetService("UserInputService")
  6. local Players = game:GetService("Players")
  7.  
  8. local player = Players.LocalPlayer
  9. local playerModule = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule"))
  10. local controls = playerModule:GetControls()
  11.  
  12. local UI = script.Parent
  13. UI.Enabled = false
  14.  
  15. local tabsContainer = UI.MainFrame.Tabs
  16.  
  17. -- order/sanitize tabs so GetChildren() randomness won't break logic
  18. local function getOrderedTabs()
  19. local list = {}
  20. for _, child in ipairs(tabsContainer:GetChildren()) do
  21. if child:IsA("Frame") or child:IsA("ImageLabel") then
  22. table.insert(list, child)
  23. end
  24. end
  25. table.sort(list, function(a, b)
  26. return (a.LayoutOrder or 0) < (b.LayoutOrder or 0)
  27. end)
  28. return list
  29. end
  30.  
  31. local tabs = getOrderedTabs()
  32. local selectedTabIndex = 1
  33. local selectedItemIndex = 1
  34.  
  35. -- IMAGES --
  36. local image1 = UI.MainFrame.InfoBox.UpDown.image1
  37. local image2 = UI.MainFrame.InfoBox.UpDown.image2
  38. local image3 = UI.MainFrame.InfoBox.UpDown.image3
  39. local image4 = UI.MainFrame.InfoBox.UpDown.image4
  40. local image5 = UI.MainFrame.InfoBox.Use.image1
  41. local image6 = UI.MainFrame.InfoBox.Use.image2
  42. local image7 = UI.MainFrame.InfoBox.ChangeTab.image1
  43. local image8 = UI.MainFrame.InfoBox.ChangeTab.image2
  44. local image9 = UI.MainFrame.InfoBox.ChangeTab.image3
  45. local image10 = UI.MainFrame.InfoBox.ChangeTab.image4
  46. local image11 = UI.MainFrame.InfoBox.Back.image1
  47. local image12 = UI.MainFrame.InfoBox.Back.image2
  48.  
  49. local pc_images = {image1, image3, image5, image7, image9, image11}
  50. local console_images = {image2, image4, image6, image8, image10, image12}
  51.  
  52. if UserInputService.GamepadEnabled then
  53. for _, img in ipairs(console_images) do img.Visible = true end
  54. for _, img in ipairs(pc_images) do img.Visible = false end
  55. else
  56. for _, img in ipairs(console_images) do img.Visible = false end
  57. for _, img in ipairs(pc_images) do img.Visible = true end
  58. end
  59.  
  60. -- ========== PlayerStorage handling (robust) ==========
  61. local playerStorage
  62. local childAddedConn, childRemovedConn
  63.  
  64. local function disconnectStorageSignals()
  65. if childAddedConn then childAddedConn:Disconnect() end
  66. if childRemovedConn then childRemovedConn:Disconnect() end
  67. childAddedConn, childRemovedConn = nil, nil
  68. end
  69.  
  70. local function onStorageChildAdded(child)
  71. if DEBUG then print("[Inventory] Item added:", child.Name, child.ClassName) end
  72. updatePlayerItems()
  73. end
  74.  
  75. local function onStorageChildRemoved(child)
  76. if DEBUG then print("[Inventory] Item removed:", child.Name, child.ClassName) end
  77. updatePlayerItems()
  78. end
  79.  
  80. local function hookPlayerStorage(storage)
  81. if DEBUG then print("[Inventory] Hooking PlayerStorage:", storage) end
  82. disconnectStorageSignals()
  83. playerStorage = storage
  84. childAddedConn = playerStorage.ChildAdded:Connect(onStorageChildAdded)
  85. childRemovedConn = playerStorage.ChildRemoved:Connect(onStorageChildRemoved)
  86. updatePlayerItems()
  87. end
  88.  
  89. -- wait / (re)hook PlayerStorage even if it's created later
  90. local function findOrWaitForPlayerStorage()
  91. local storage = player:FindFirstChild("PlayerStorage")
  92. if storage then
  93. hookPlayerStorage(storage)
  94. else
  95. if DEBUG then print("[Inventory] Waiting for PlayerStorage...") end
  96. storage = player:WaitForChild("PlayerStorage")
  97. hookPlayerStorage(storage)
  98. end
  99. end
  100.  
  101. -- also handle the case where PlayerStorage might get recreated (rare but safe to cover)
  102. player.ChildAdded:Connect(function(child)
  103. if child.Name == "PlayerStorage" then
  104. hookPlayerStorage(child)
  105. end
  106. end)
  107.  
  108. -- ========== UI helpers ==========
  109. local function getItemsFolderForTab(tab)
  110. -- If your ItemsFolder is *inside* the tab, keep this.
  111. -- If it's elsewhere, change this to the correct path.
  112. return tab:FindFirstChild("ItemsFolder")
  113. end
  114.  
  115. local function getItemsForCurrentTab()
  116. if selectedTabIndex ~= 1 then
  117. return {}
  118. end
  119.  
  120. local currentTab = tabs[selectedTabIndex]
  121. local itemsFolder = getItemsFolderForTab(currentTab)
  122. local items = {}
  123. if itemsFolder then
  124. for _, child in ipairs(itemsFolder:GetChildren()) do
  125. if child:IsA("TextLabel") then
  126. table.insert(items, child)
  127. end
  128. end
  129. end
  130. return items
  131. end
  132.  
  133. local function highlightTabs()
  134. for i, tab in ipairs(tabs) do
  135. if tab:IsA("Frame") or tab:IsA("ImageLabel") then
  136. if i == selectedTabIndex then
  137. tab.BackgroundTransparency = 0
  138. tab.BackgroundColor3 = Color3.fromRGB(45, 45, 45) -- Selected
  139. else
  140. tab.BackgroundTransparency = 1
  141. end
  142. end
  143. end
  144. end
  145.  
  146. function highlightItems()
  147. local items = getItemsForCurrentTab()
  148. for i, item in ipairs(items) do
  149. if i == selectedItemIndex then
  150. item.TextColor3 = Color3.fromRGB(255, 255, 255)
  151. else
  152. item.TextColor3 = Color3.fromRGB(200, 200, 200)
  153. end
  154. end
  155. end
  156.  
  157.  
  158. -- Populate the list from PlayerStorage
  159. function updatePlayerItems()
  160. if not tabs[1] then return end
  161.  
  162. local itemsFolder = getItemsFolderForTab(tabs[1])
  163. if not itemsFolder then
  164. if DEBUG then warn("[Inventory] ItemsFolder not found under first tab!") end
  165. return
  166. end
  167.  
  168. -- optional: add a UIListLayout if you want auto layout
  169. if not itemsFolder:FindFirstChildOfClass("UIListLayout") then
  170. local layout = Instance.new("UIListLayout")
  171. layout.Padding = UDim.new(0, 2)
  172. layout.FillDirection = Enum.FillDirection.Vertical
  173. layout.SortOrder = Enum.SortOrder.LayoutOrder
  174. layout.Parent = itemsFolder
  175. end
  176.  
  177. -- Clear old labels
  178. for _, child in ipairs(itemsFolder:GetChildren()) do
  179. if child:IsA("TextLabel") then
  180. child:Destroy()
  181. end
  182. end
  183.  
  184. if not playerStorage then
  185. if DEBUG then warn("[Inventory] playerStorage is nil at update time") end
  186. return
  187. end
  188.  
  189. -- Create labels for each Part or Model in playerStorage
  190. for _, item in ipairs(playerStorage:GetChildren()) do
  191. if item:IsA("Model") or item:IsA("Part") then
  192. local newLabel = Instance.new("TextLabel")
  193. newLabel.Size = UDim2.new(1, 0, 0, 24)
  194. newLabel.BackgroundTransparency = 1
  195. newLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
  196. newLabel.Font = Enum.Font.SourceSans
  197. newLabel.TextScaled = false
  198. newLabel.TextXAlignment = Enum.TextXAlignment.Left
  199. newLabel.Text = "- " .. item.Name
  200. newLabel.Parent = itemsFolder
  201. newLabel.Position = UDim2.new(0.821, 0,2.233, 0)
  202. end
  203. end
  204.  
  205. selectedItemIndex = 1
  206. highlightItems()
  207. end
  208.  
  209. -- ========== Open / Close menu ==========
  210. UserInputService.InputBegan:Connect(function(input)
  211. if input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.ButtonX then
  212. controls:Disable()
  213. UI.Enabled = true
  214. selectedTabIndex = 1
  215. selectedItemIndex = 1
  216.  
  217. -- Re-get/rehook player storage if for some reason it's not there yet
  218. if not playerStorage then
  219. findOrWaitForPlayerStorage()
  220. else
  221. updatePlayerItems()
  222. end
  223.  
  224. highlightTabs()
  225. highlightItems()
  226. end
  227. end)
  228.  
  229. UserInputService.InputBegan:Connect(function(input)
  230. if input.KeyCode == Enum.KeyCode.Escape or input.KeyCode == Enum.KeyCode.ButtonY then
  231. controls:Enable()
  232. UI.Enabled = false
  233. selectedTabIndex = 1
  234. selectedItemIndex = 1
  235. highlightTabs()
  236. highlightItems()
  237. end
  238. end)
  239.  
  240. -- ========== Navigation ==========
  241. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  242. if gameProcessed then return end
  243.  
  244. -- NEXT TAB (E / DPadRight)
  245. if input.KeyCode == Enum.KeyCode.E or input.KeyCode == Enum.KeyCode.DPadRight then
  246. selectedTabIndex += 1
  247. if selectedTabIndex > #tabs then
  248. selectedTabIndex = 1
  249. end
  250. selectedItemIndex = 1
  251. highlightTabs()
  252. highlightItems()
  253.  
  254. -- PREVIOUS TAB (Q / DPadLeft)
  255. elseif input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.DPadLeft then
  256. selectedTabIndex -= 1
  257. if selectedTabIndex < 1 then
  258. selectedTabIndex = #tabs
  259. end
  260. selectedItemIndex = 1
  261. highlightTabs()
  262. highlightItems()
  263.  
  264. -- UP (Up / DPadUp)
  265. elseif input.KeyCode == Enum.KeyCode.Up or input.KeyCode == Enum.KeyCode.DPadUp then
  266. local items = getItemsForCurrentTab()
  267. if #items > 0 then
  268. selectedItemIndex -= 1
  269. if selectedItemIndex < 1 then
  270. selectedItemIndex = #items
  271. end
  272. highlightItems()
  273. end
  274.  
  275. -- DOWN (Down / DPadDown)
  276. elseif input.KeyCode == Enum.KeyCode.Down or input.KeyCode == Enum.KeyCode.DPadDown then
  277. local items = getItemsForCurrentTab()
  278. if #items > 0 then
  279. selectedItemIndex += 1
  280. if selectedItemIndex > #items then
  281. selectedItemIndex = 1
  282. end
  283. highlightItems()
  284. end
  285. end
  286. end)
  287.  
  288. -- Initial setup
  289. highlightTabs()
  290. highlightItems()
  291. findOrWaitForPlayerStorage()
  292.  
Advertisement
Add Comment
Please, Sign In to add comment