Guest User

Script

a guest
Jul 28th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local character = player.Character
  3. local items = {}
  4. local buttons = {}
  5. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible
  6.  
  7. function search(location)
  8. for i,v in pairs(location:GetChildren()) do -- Find all item in a specific location
  9. if v:isA("Tool") then -- If the item found is a "Tool"
  10. table.insert(items,v) -- We're going to put all the tools found in a table.
  11. end
  12. end
  13. end
  14.  
  15. function refresh()
  16. for i,v in pairs(buttons) do -- Finds all items in the table
  17. v:Destroy() -- Destroy 'em all
  18. end
  19. for i,v in pairs(items) do -- Finds all items in the table
  20. local button = script.Sample:Clone() -- clones the sample button inside the localscript
  21. button.Name = v.Name -- sets the cloned button's name to the name of the item
  22. button.LayoutOrder = i
  23. button.Parent = script.Parent.Handler -- Sets the parent of the cloned button to the handler
  24. button.Image = v.TextureId -- Sets the image of the button to the texture id of the tool
  25. table.insert(buttons,button) -- Inserts the button to our table "buttons"
  26. button.MouseButton1Click:connect(function()
  27. if script.Parent.Handler.Selected.Value == nil or script.Parent.Handler.Selected.Value ~= v then -- Checks if the selected value is nothing or if the selected value is not the button
  28. script.Parent.Frame.ItemName.Text = v.Name -- Sets the TextLabel's Text to the name of the tool/button
  29. script.Parent.Frame.ImageLabel.Image = v.TextureId -- Sets the image label's image to the texture id of the tool
  30. script.Parent.Handler.Selected.Value = v
  31. if script.Parent.Handler.Selected.Value ~= script.Parent.Handler.Equipped.Value then --if the selected value is not the same as the equipped value then
  32. script.Parent.Handler.Location.Value = v.Parent -- Sets the value of our location to the parent of the tool whether it is in the backpack or in the character
  33. script.Parent.Frame.Equip.Text = "Equip" -- Self explanatory
  34. elseif script.Parent.Handler.Selected.Value == script.Parent.Handler.Equipped.Value then -- If the selected value is the same as the equipped value then...
  35. script.Parent.Handler.Location.Value = v.Parent
  36. script.Parent.Frame.Equip.Text = "Unequip"
  37. end
  38. end
  39. end)
  40. end
  41. end
  42.  
  43. function backpackRefresh()
  44. items = {}
  45. search(character)
  46. search(player.Backpack)
  47. refresh()
  48. end
  49.  
  50. backpackRefresh()
  51.  
  52. player.Backpack.ChildAdded:connect(backpackRefresh)
  53. player.Backpack.ChildRemoved:connect(backpackRefresh)
  54.  
  55. character.ChildAdded:connect(backpackRefresh)
  56. character.ChildRemoved:connect(backpackRefresh)
Advertisement
Add Comment
Please, Sign In to add comment