Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1.  
  2.  
  3. game:GetService('StarterGui'):SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  4.  
  5.  
  6. local uis = game:GetService("UserInputService")
  7. local player = game.Players.LocalPlayer
  8. local char = workspace:WaitForChild(player.Name)
  9. local bp = player.Backpack
  10. local hum = char:WaitForChild("Humanoid")
  11. local frame = script.Parent.Frame
  12. local template = frame.Template
  13. local equipped = 0.2
  14. local unequipped = 0.7
  15.  
  16. local iconSize = template.Size
  17. local iconBorder = {x = 15, y = 5}
  18.  
  19. local inputKeys = {
  20. ["One"] = {txt = "1"},
  21. ["Two"] = {txt = "2"},
  22. ["Three"] = {txt = "3"},
  23. ["Four"] = {txt = "4"},
  24. ["Five"] = {txt = "5"},
  25. ["Six"] = {txt = "6"},
  26. ["Seven"] = {txt = "7"},
  27. ["Eight"] = {txt = "8"},
  28. ["Nine"] = {txt = "9"},
  29. ["Zero"] = {txt = "0"},
  30. }
  31.  
  32. local inputOrder = {
  33. inputKeys["One"],inputKeys["Two"],inputKeys["Three"],inputKeys["Four"],inputKeys["Five"],
  34. inputKeys["Six"],inputKeys["Seven"],inputKeys["Eight"],inputKeys["Nine"],inputKeys["Zero"],
  35. }
  36.  
  37.  
  38. function handleEquip(tool)
  39. if tool then
  40. if tool.Parent ~= char then
  41. hum:EquipTool(tool)
  42. else
  43. hum:UnequipTools()
  44. end
  45. end
  46. end
  47.  
  48. function create()
  49.  
  50. local toShow = #inputOrder
  51. local totalX = (toShow*iconSize.X.Offset)+((toShow+1)*iconBorder.x)
  52. local totalY = iconSize.Y.Offset + (2*iconBorder.y)
  53.  
  54. frame.Size = UDim2.new(0, totalX, 0, totalY)
  55. frame.Position = UDim2.new(0.5, -(totalX/2), 1, -(totalY+(iconBorder.y*2)))
  56. frame.Visible = true
  57. for i = 1, #inputOrder do
  58.  
  59. local value = inputOrder[i]
  60. local clone = template:Clone()
  61. clone.Parent = frame
  62. clone.Label.Text = value["txt"]
  63. clone.Name = value["txt"]
  64. clone.Visible = true
  65. clone.Position = UDim2.new(0, (i-1)*(iconSize.X.Offset)+(iconBorder.x*i), 0, iconBorder.y)
  66. clone.ImageTransparency = unequipped
  67.  
  68. local tool = value["tool"]
  69. if tool then
  70. clone.Tool.Image = tool.TextureId
  71. end
  72.  
  73. clone.Tool.MouseButton1Down:Connect(function()
  74. for key, value in pairs(inputKeys) do
  75. if value["txt"] == clone.Name then
  76. handleEquip(value["tool"])
  77. end
  78. end
  79. end)
  80.  
  81. end
  82. template:Destroy()
  83. end
  84.  
  85. function setup()
  86. local tools = bp:GetChildren()
  87. for i = 1, #tools do
  88. if tools[i]:IsA("Tool") then
  89. for i = 1, #inputOrder do
  90. local value = inputOrder[i]
  91. if not value["tool"] then
  92. value["tool"] = tools[i]
  93. break
  94. end
  95. end
  96. end
  97. end
  98. create()
  99. end
  100.  
  101. function adjust()
  102. for key, value in pairs(inputKeys) do
  103. local tool = value["tool"]
  104. local icon = frame:FindFirstChild(value["txt"])
  105. if tool then
  106. icon.Tool.Image = tool.TextureId
  107. if tool.Parent == char then
  108. icon.ImageTransparency = equipped
  109. else
  110. icon.ImageTransparency = unequipped
  111. end
  112. else
  113. icon.Tool.Image = ""
  114. icon.ImageTransparency = unequipped
  115. end
  116. end
  117. end
  118.  
  119. function onKeyPress(inputObject)
  120. local key = inputObject.KeyCode.Name
  121. local value = inputKeys[key]
  122. if value and uis:GetFocusedTextBox() == nil then
  123. handleEquip(value["tool"])
  124. end
  125. end
  126.  
  127. function handleAddition(adding)
  128.  
  129. if adding:IsA("Tool") then
  130. local new = true
  131.  
  132. for key, value in pairs(inputKeys) do
  133. local tool = value["tool"]
  134. if tool then
  135. if tool == adding then
  136. new = false
  137. end
  138. end
  139. end
  140.  
  141. if new then
  142. for i = 1, #inputOrder do
  143. local tool = inputOrder[i]["tool"]
  144. if not tool then
  145. inputOrder[i]["tool"] = adding
  146. break
  147. end
  148. end
  149. end
  150.  
  151. adjust()
  152. end
  153. end
  154.  
  155. function handleRemoval(removing)
  156. if removing:IsA("Tool") then
  157. if removing.Parent ~= char and removing.Parent ~= bp then
  158.  
  159. for i = 1, #inputOrder do
  160. if inputOrder[i]["tool"] == removing then
  161. inputOrder[i]["tool"] = nil
  162. break
  163. end
  164. end
  165. end
  166.  
  167. adjust()
  168. end
  169. end
  170.  
  171.  
  172. uis.InputBegan:Connect(onKeyPress)
  173.  
  174. char.ChildAdded:Connect(handleAddition)
  175. char.ChildRemoved:Connect(handleRemoval)
  176.  
  177. bp.ChildAdded:Connect(handleAddition)
  178. bp.ChildRemoved:Connect(handleRemoval)
  179.  
  180. setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement