Advertisement
DrawingJhon

TopBar Button

Jun 12th, 2021 (edited)
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.33 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local GuiService = game:GetService("GuiService")
  3.  
  4. local TopbarModule = {}
  5.  
  6. function TopbarModule:Add(ButtonName,Image,Left)
  7.     if ButtonName ~= nil and Image ~= nil then
  8.         if RunService:IsClient() then
  9.             local Player = game.Players.LocalPlayer
  10.             if Player ~= nil then
  11.                 local PlrCheck = false
  12.                 for _,p in pairs(game.Players:GetPlayers()) do
  13.                     if p == Player then
  14.                         PlrCheck = true
  15.                     end
  16.                 end
  17.                 if PlrCheck == false then
  18.                     warn("Invalid Player")
  19.                     return false
  20.                 else
  21.                     -- Player is valid, Check to see if there is already the topbar frame
  22.                     local TopbarFrame
  23.                     pcall(function()
  24.                         TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  25.                     end)
  26.                     if TopbarFrame == nil then
  27.                         -- No TopbarFrame, Add it
  28.                         local TBUI = Instance.new("ScreenGui",Player.PlayerGui)
  29.                         TBUI.Name = "TopbarGUI"
  30.                         TBUI.DisplayOrder = 1000000000
  31.                         TBUI.Enabled = true
  32.                         TBUI.IgnoreGuiInset = true
  33.                         TBUI.ResetOnSpawn = false
  34.                        
  35.                         local TBFrame = Instance.new("Frame",TBUI)
  36.                         TBFrame.BackgroundTransparency = 1
  37.                         TBFrame.BorderSizePixel = 0
  38.                         TBFrame.Name = "TopbarFrame"
  39.                         TBFrame.Size = UDim2.new(1,0,0,36)
  40.                         TBFrame.ZIndex = 1000000000
  41.                        
  42.                         local TBL = Instance.new("Frame",TBFrame)
  43.                         TBL.BackgroundTransparency = 1
  44.                         TBL.BorderSizePixel = 0
  45.                         TBL.Name = "Left"
  46.                         TBL.Position = UDim2.new(0,104,0,4)
  47.                         TBL.Size = UDim2.new(0.85,0,0,32)
  48.                        
  49.                         local TBR = Instance.new("Frame",TBFrame)
  50.                         TBR.BackgroundTransparency = 1
  51.                         TBR.BorderSizePixel = 0
  52.                         TBR.Name = "Right"
  53.                         TBR.AnchorPoint = Vector2.new(1,0)
  54.                         TBR.Position = UDim2.new(1,-60,0,4)
  55.                         TBR.Size = UDim2.new(0.85,0,0,32)
  56.                        
  57.                         local TBLUI = Instance.new("UIListLayout",TBL)
  58.                         TBLUI.Padding = UDim.new(0,12)
  59.                         TBLUI.FillDirection = Enum.FillDirection.Horizontal
  60.                         TBLUI.HorizontalAlignment = Enum.HorizontalAlignment.Left
  61.                         TBLUI.SortOrder = Enum.SortOrder.LayoutOrder
  62.                         TBLUI.VerticalAlignment = Enum.VerticalAlignment.Top
  63.                        
  64.                         local TBRUI = Instance.new("UIListLayout",TBR)
  65.                         TBRUI.Padding = UDim.new(0,12)
  66.                         TBRUI.FillDirection = Enum.FillDirection.Horizontal
  67.                         TBRUI.HorizontalAlignment = Enum.HorizontalAlignment.Right
  68.                         TBRUI.SortOrder = Enum.SortOrder.LayoutOrder
  69.                         TBRUI.VerticalAlignment = Enum.VerticalAlignment.Top
  70.                        
  71.                         RunService.RenderStepped:Connect(function()
  72.                             if GuiService.MenuIsOpen == true then
  73.                                 TBFrame.Visible = false
  74.                             else
  75.                                 TBFrame.Visible = true
  76.                             end
  77.                         end)
  78.                         TopbarFrame = TBUI
  79.                     end
  80.                     -- Check to see if name is taken
  81.                     local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  82.                     local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  83.                     if CheckLeft == nil and CheckRight == nil then
  84.                         local NewButton = Instance.new("Frame")
  85.                         NewButton.Name = ButtonName
  86.                         NewButton.BackgroundTransparency = 1
  87.                         NewButton.BorderSizePixel = 0
  88.                         NewButton.Position = UDim2.new(0,104,0,4)
  89.                         NewButton.Size = UDim2.new(0,32,0,32)
  90.                        
  91.                         local IconButton = Instance.new("ImageButton",NewButton)
  92.                         IconButton.BackgroundTransparency = 1
  93.                         IconButton.Name = "IconButton"
  94.                         IconButton.Size = UDim2.new(1,0,1,0)
  95.                         IconButton.ZIndex = 2
  96.                         IconButton.Image = "rbxasset://textures/ui/TopBar/iconBase.png"
  97.                        
  98.                         local BadgeContainer = Instance.new("Frame",IconButton)
  99.                         BadgeContainer.BackgroundTransparency = 1
  100.                         BadgeContainer.Size = UDim2.new(1,0,1,0)
  101.                         BadgeContainer.Name = "BadgeContainer"
  102.                         BadgeContainer.ZIndex = 5
  103.                         BadgeContainer.Visible = false
  104.                        
  105.                         local Badge = Instance.new("Frame",BadgeContainer)
  106.                         Badge.BackgroundTransparency = 1
  107.                         Badge.Name = "Badge"
  108.                         Badge.Position = UDim2.new(0,18,0,-2)
  109.                         Badge.Size = UDim2.new(0,24,0,24)
  110.                        
  111.                         local BadgeBG = Instance.new("ImageLabel",Badge)
  112.                         BadgeBG.BackgroundTransparency = 1
  113.                         BadgeBG.Size = UDim2.new(1,0,1,0)
  114.                         BadgeBG.Name = "Background"
  115.                         BadgeBG.ZIndex = 2
  116.                         BadgeBG.Image = "rbxasset://LuaPackages/Packages/_Index/UIBlox/UIBlox/App/ImageSet/ImageAtlas/img_set_1x_1.png"
  117.                         BadgeBG.ImageColor3 = Color3.fromRGB(35, 37, 39)
  118.                         BadgeBG.ImageRectOffset = Vector2.new(301, 484)
  119.                         BadgeBG.ImageRectSize = Vector2.new(25,25)
  120.                         BadgeBG.ScaleType = Enum.ScaleType.Slice
  121.                         BadgeBG.SliceCenter = Rect.new(Vector2.new(14,14),Vector2.new(15,15))
  122.                        
  123.                         local Inner = Instance.new("ImageLabel",Badge)
  124.                         Inner.AnchorPoint = Vector2.new(0.5,0.5)
  125.                         Inner.BackgroundTransparency = 1
  126.                         Inner.Name = "Inner"
  127.                         Inner.Position = UDim2.new(0.5,0,0.5,0)
  128.                         Inner.Size = UDim2.new(1,-4,1,-4)
  129.                         Inner.ZIndex = 3
  130.                         Inner.Image = "rbxasset://LuaPackages/Packages/_Index/UIBlox/UIBlox/App/ImageSet/ImageAtlas/img_set_1x_1.png"
  131.                         Inner.ImageRectOffset = Vector2.new(463,168)
  132.                         Inner.ImageRectSize = Vector2.new(21,21)
  133.                         Inner.ScaleType = Enum.ScaleType.Slice
  134.                         Inner.SliceCenter = Rect.new(Vector2.new(14,14),Vector2.new(15,15))
  135.                        
  136.                         local InnerTL = Instance.new("TextLabel",Inner)
  137.                         InnerTL.BackgroundTransparency = 1
  138.                         InnerTL.Name = "TextLabel"
  139.                         InnerTL.Size = UDim2.new(1,0,1,0)
  140.                         InnerTL.Font = Enum.Font.Gotham
  141.                         InnerTL.Text = "0"
  142.                         InnerTL.TextColor3 = Color3.fromRGB(57, 59, 61)
  143.                         InnerTL.TextSize = 14
  144.                        
  145.                         local IconImg = Instance.new("ImageLabel",IconButton)
  146.                         IconImg.AnchorPoint = Vector2.new(0.5,0.5)
  147.                         IconImg.BackgroundTransparency = 1
  148.                         IconImg.Name = "IconImage"
  149.                         IconImg.Position = UDim2.new(0.5,0,0.5,0)
  150.                         IconImg.Size = UDim2.new(0,24,0,24)
  151.                         IconImg.ZIndex = 3
  152.                         IconImg.Image = "rbxasset://textures/ui/TopBar/coloredlogo.png"
  153.                         IconImg.ScaleType = Enum.ScaleType.Fit
  154.                        
  155.                         local DropDown = Instance.new("ImageLabel",NewButton)
  156.                         DropDown.AnchorPoint = Vector2.new(0.5,0)
  157.                         DropDown.BackgroundTransparency = 1
  158.                         DropDown.Position = UDim2.new(0.5,0,1,2)
  159.                         DropDown.Size = UDim2.new(0,10,0,0)
  160.                         DropDown.Image = "rbxasset://textures/ui/TopBar/iconBase.png"
  161.                         DropDown.ScaleType = Enum.ScaleType.Slice
  162.                         DropDown.SliceCenter =  Rect.new(Vector2.new(10,10),Vector2.new(10,10))
  163.                        
  164.                         local DropList = Instance.new("UIListLayout",DropDown)
  165.                         DropList.FillDirection = Enum.FillDirection.Vertical
  166.                         DropList.HorizontalAlignment = Enum.HorizontalAlignment.Left
  167.                         DropList.SortOrder = Enum.SortOrder.LayoutOrder
  168.                         DropList.VerticalAlignment = Enum.VerticalAlignment.Top
  169.                        
  170.                         pcall(function()
  171.                             NewButton.IconButton.IconImage.Image = Image
  172.                         end)
  173.                         if Left == true or nil then
  174.                             NewButton.Parent = TopbarFrame.TopbarFrame.Left
  175.                         else
  176.                             NewButton.Parent = TopbarFrame.TopbarFrame.Right
  177.                         end
  178.                         return NewButton.IconButton
  179.                     else
  180.                         -- Name already in use
  181.                         return false
  182.                     end
  183.                 end
  184.             else
  185.                 warn("Player is nil")
  186.             end
  187.  
  188.         else
  189.             warn("Input is nil")
  190.             return false
  191.         end
  192.     end
  193. end
  194.  
  195. function TopbarModule:Remove(ButtonName)
  196.     if RunService:IsClient() then
  197.         local Player = game.Players.LocalPlayer
  198.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  199.         if TopbarFrame ~= nil then
  200.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  201.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  202.             if CheckLeft ~= nil then
  203.                 CheckLeft:Destroy()
  204.                 return true
  205.             end
  206.             if CheckRight ~= nil then
  207.                 CheckRight:Destroy()
  208.                 return true
  209.             end
  210.             if CheckRight == nil and CheckLeft == nil then
  211.                 return false
  212.             end
  213.         else
  214.             return false
  215.         end
  216.     end
  217. end
  218.  
  219. function TopbarModule:Hide(ButtonName)
  220.     if RunService:IsClient() then
  221.         local Player = game.Players.LocalPlayer
  222.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  223.         if TopbarFrame ~= nil then
  224.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  225.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  226.             if CheckLeft ~= nil then
  227.                 CheckLeft.Visible = false
  228.                 return true
  229.             end
  230.             if CheckRight ~= nil then
  231.                 CheckRight.Visible = false
  232.                 return true
  233.             end
  234.             if CheckRight == nil and CheckLeft == nil then
  235.                 return false
  236.             end
  237.         else
  238.             return false
  239.         end
  240.     end
  241. end
  242.  
  243. function TopbarModule:Show(ButtonName)
  244.     if RunService:IsClient() then
  245.         local Player = game.Players.LocalPlayer
  246.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  247.         if TopbarFrame ~= nil then
  248.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  249.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  250.             if CheckLeft ~= nil then
  251.                 CheckLeft.Visible = true
  252.                 return true
  253.             end
  254.             if CheckRight ~= nil then
  255.                 CheckRight.Visible = true
  256.                 return true
  257.             end
  258.             if CheckRight == nil and CheckLeft == nil then
  259.                 return false
  260.             end
  261.         else
  262.             return false
  263.         end
  264.     end
  265. end
  266.  
  267. function TopbarModule:ChangeImage(ButtonName,Image)
  268.     if RunService:IsClient() then
  269.         local Player = game.Players.LocalPlayer
  270.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  271.         if TopbarFrame ~= nil then
  272.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  273.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  274.             if CheckLeft ~= nil then
  275.                 pcall(function()
  276.                     CheckLeft.IconButton.IconImage.Image = Image
  277.                 end)
  278.                 return true
  279.             end
  280.             if CheckRight ~= nil then
  281.                 pcall(function()
  282.                     CheckRight.IconButton.IconImage.Image = Image
  283.                 end)
  284.                 return true
  285.             end
  286.             if CheckRight == nil and CheckLeft == nil then
  287.                 return false
  288.             end
  289.         else
  290.             return false
  291.         end
  292.     end
  293. end
  294.  
  295. function TopbarModule:GetAmount(ButtonName)
  296.     if RunService:IsClient() then
  297.         local Player = game.Players.LocalPlayer
  298.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  299.         if TopbarFrame ~= nil then
  300.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  301.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  302.             if CheckLeft ~= nil then
  303.                 return CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text
  304.             end
  305.             if CheckRight ~= nil then
  306.                 return CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text
  307.             end
  308.             if CheckRight == nil and CheckLeft == nil then
  309.                 return false
  310.             end
  311.         else
  312.             return false
  313.         end
  314.     end
  315. end
  316.  
  317. function TopbarModule:SetAmount(ButtonName,Amount)
  318.     if RunService:IsClient() then
  319.         local Player = game.Players.LocalPlayer
  320.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  321.         if TopbarFrame ~= nil and Amount ~= nil then
  322.             if tonumber(Amount) >= 0 then
  323.                 local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  324.                 local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  325.                 if CheckLeft ~= nil then
  326.                     CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(Amount)
  327.                     if tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  328.                         CheckLeft.IconButton.BadgeContainer.Visible = true
  329.                     else
  330.                         CheckLeft.IconButton.BadgeContainer.Visible = false
  331.                     end
  332.                     return true
  333.                 end
  334.                 if CheckRight ~= nil then
  335.                     CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(Amount)
  336.                     if tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  337.                         CheckRight.IconButton.BadgeContainer.Visible = true
  338.                     else
  339.                         CheckRight.IconButton.BadgeContainer.Visible = false
  340.                     end
  341.                     return true
  342.                 end
  343.                 if CheckRight == nil and CheckLeft == nil then
  344.                     return false
  345.                 end
  346.             else
  347.                 return false
  348.             end
  349.         end
  350.     end
  351. end
  352.  
  353. function TopbarModule:AddAmount(ButtonName,Amount)
  354.     if RunService:IsClient() then
  355.         local Player = game.Players.LocalPlayer
  356.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  357.         if TopbarFrame ~= nil and Amount ~= nil then
  358.             if tonumber(Amount) >= 0 then
  359.                 local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  360.                 local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  361.                 if CheckLeft ~= nil then
  362.                     CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) + Amount)
  363.                     if tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  364.                         CheckLeft.IconButton.BadgeContainer.Visible = true
  365.                     else
  366.                         CheckLeft.IconButton.BadgeContainer.Visible = false
  367.                     end
  368.                     if tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) <= -1 then
  369.                         CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = "0"
  370.                     end
  371.                     return true
  372.                 end
  373.                 if CheckRight ~= nil then
  374.                     CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) + Amount)
  375.                     if tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  376.                         CheckRight.IconButton.BadgeContainer.Visible = true
  377.                     else
  378.                         CheckRight.IconButton.BadgeContainer.Visible = false
  379.                     end
  380.                     if tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) <= -1 then
  381.                         CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = "0"
  382.                     end
  383.                     return true
  384.                 end
  385.                 if CheckRight == nil and CheckLeft == nil then
  386.                     return false
  387.                 end
  388.             else
  389.                 return false
  390.             end
  391.         end
  392.     end
  393. end
  394.  
  395. function TopbarModule:RemoveAmount(ButtonName,Amount)
  396.     if RunService:IsClient() then
  397.         local Player = game.Players.LocalPlayer
  398.         local TopbarFrame = Player.PlayerGui:FindFirstChild("TopbarGUI")
  399.         if TopbarFrame ~= nil and Amount ~= nil then
  400.             if tonumber(Amount) >= 0 then
  401.                 local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  402.                 local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  403.                 if CheckLeft ~= nil then
  404.                     CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) - Amount)
  405.                     if tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  406.                         CheckLeft.IconButton.BadgeContainer.Visible = true
  407.                     else
  408.                         CheckLeft.IconButton.BadgeContainer.Visible = false
  409.                     end
  410.                     if tonumber(CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) <= -1 then
  411.                         CheckLeft.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = "0"
  412.                     end
  413.                     return true
  414.                 end
  415.                 if CheckRight ~= nil then
  416.                     CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = tostring(tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) - Amount)
  417.                     if tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) > 0 then
  418.                         CheckRight.IconButton.BadgeContainer.Visible = true
  419.                     else
  420.                         CheckRight.IconButton.BadgeContainer.Visible = false
  421.                     end
  422.                     if tonumber(CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text) <= -1 then
  423.                         CheckRight.IconButton.BadgeContainer.Badge.Inner.TextLabel.Text = "0"
  424.                     end
  425.                     return true
  426.                 end
  427.                 if CheckRight == nil and CheckLeft == nil then
  428.                     return false
  429.                 end
  430.             else
  431.                 return false
  432.             end
  433.         end
  434.     end
  435. end
  436.  
  437. function TopbarModule:CreateDropdownButton(DropdownButtonName,TopbarButtonName,Text)
  438.     if RunService:IsClient() then
  439.         local p = game.Players.LocalPlayer
  440.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  441.         if TopbarFrame then
  442.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(TopbarButtonName)
  443.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(TopbarButtonName)
  444.             local Button = nil
  445.             if CheckLeft then
  446.                 Button = CheckLeft
  447.             elseif CheckRight then
  448.                 Button = CheckRight
  449.             end
  450.             if Button then
  451.                 local NameChecker = Button.Dropdown:FindFirstChild(DropdownButtonName)
  452.                 if NameChecker == nil then
  453.                     local NewUI = Instance.new("TextButton")
  454.                     NewUI.BackgroundTransparency = 1
  455.                     NewUI.Size = UDim2.new(1,0,0,25)
  456.                     NewUI.Font = Enum.Font.SourceSansSemibold
  457.                     NewUI.Text = Text
  458.                     NewUI.TextSize = 15
  459.                     NewUI.Name = DropdownButtonName
  460.                     wait()
  461.                     Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset,0,Button.Dropdown.Size.Y.Offset + 25)
  462.                     NewUI.Parent = Button.Dropdown
  463.                     if NewUI.TextFits == false then
  464.                         repeat
  465.                             Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 1,0,Button.Dropdown.Size.Y.Offset)
  466.                             wait()
  467.                         until NewUI.TextFits == true
  468.                         Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 8,0,Button.Dropdown.Size.Y.Offset)
  469.                     end
  470.                     wait()
  471.                     return NewUI
  472.                 else
  473.                     return false
  474.                 end
  475.             else
  476.                 return false
  477.             end
  478.         else
  479.             return false
  480.         end
  481.     end
  482. end
  483.  
  484. function TopbarModule:RemoveDropdownButton(DropdownButtonName,TopbarButtonName)
  485.     if RunService:IsClient() then
  486.         local p = game.Players.LocalPlayer
  487.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  488.         if TopbarFrame then
  489.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(TopbarButtonName)
  490.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(TopbarButtonName)
  491.             local Button = nil
  492.             if CheckLeft then
  493.                 Button = CheckLeft
  494.             elseif CheckRight then
  495.                 Button = CheckRight
  496.             end
  497.             if Button then
  498.                 local NameChecker = Button.Dropdown:FindFirstChild(DropdownButtonName)
  499.                 if NameChecker then
  500.                     NameChecker:Destroy()
  501.                     Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset,0,Button.Dropdown.Size.Y.Offset - 25)
  502.                     return true
  503.                 else
  504.                     return false
  505.                 end
  506.             else
  507.                 return false
  508.             end
  509.         else
  510.             return false
  511.         end
  512.     end
  513. end
  514.  
  515. function TopbarModule:HideDropdownButton(DropdownButtonName,TopbarButtonName)
  516.     if RunService:IsClient() then
  517.         local p = game.Players.LocalPlayer
  518.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  519.         if TopbarFrame then
  520.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(TopbarButtonName)
  521.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(TopbarButtonName)
  522.             local Button = nil
  523.             if CheckLeft then
  524.                 Button = CheckLeft
  525.             elseif CheckRight then
  526.                 Button = CheckRight
  527.             end
  528.             if Button then
  529.                 local NameChecker = Button.Dropdown:FindFirstChild(DropdownButtonName)
  530.                 if NameChecker then
  531.                     if NameChecker.Visible == true then
  532.                         NameChecker.Visible = false
  533.                         Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset,0,Button.Dropdown.Size.Y.Offset - 25)
  534.                         return true
  535.                     else
  536.                         return false
  537.                     end
  538.                 else
  539.                     return false
  540.                 end
  541.             else
  542.                 return false
  543.             end
  544.         else
  545.             return false
  546.         end
  547.     end
  548. end
  549.  
  550. function TopbarModule:ShowDropdownButton(DropdownButtonName,TopbarButtonName)
  551.     if RunService:IsClient() then
  552.         local p = game.Players.LocalPlayer
  553.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  554.         if TopbarFrame then
  555.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(TopbarButtonName)
  556.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(TopbarButtonName)
  557.             local Button = nil
  558.             if CheckLeft then
  559.                 Button = CheckLeft
  560.             elseif CheckRight then
  561.                 Button = CheckRight
  562.             end
  563.             if Button then
  564.                 local NameChecker = Button.Dropdown:FindFirstChild(DropdownButtonName)
  565.                 if NameChecker then
  566.                     if NameChecker.Visible == false then
  567.                         NameChecker.Visible = true
  568.                         Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset,0,Button.Dropdown.Size.Y.Offset + 25)
  569.                         return true
  570.                     else
  571.                         return false
  572.                     end
  573.                 else
  574.                     return false
  575.                 end
  576.             else
  577.                 return false
  578.             end
  579.         else
  580.             return false
  581.         end
  582.     end
  583. end
  584.  
  585. function TopbarModule:EditDropdownButton(DropdownButtonName,TopbarButtonName,Text)
  586.     if RunService:IsClient() then
  587.         local p = game.Players.LocalPlayer
  588.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  589.         if TopbarFrame then
  590.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(TopbarButtonName)
  591.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(TopbarButtonName)
  592.             local Button = nil
  593.             if CheckLeft then
  594.                 Button = CheckLeft
  595.             elseif CheckRight then
  596.                 Button = CheckRight
  597.             end
  598.             if Button then
  599.                 local NameChecker = Button.Dropdown:FindFirstChild(DropdownButtonName)
  600.                 if NameChecker then
  601.                     NameChecker.Text = Text
  602.                     wait()
  603.                     if NameChecker.TextFits == false then
  604.                         repeat
  605.                             Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 1,0,Button.Dropdown.Size.Y.Offset)
  606.                             wait()
  607.                         until NameChecker.TextFits == true
  608.                         Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 8,0,Button.Dropdown.Size.Y.Offset)
  609.                     end
  610.                     wait()
  611.                     return true
  612.                 else
  613.                     return false
  614.                 end
  615.             else
  616.                 return false
  617.             end
  618.         else
  619.             return false
  620.         end
  621.     end
  622. end
  623.  
  624. function TopbarModule:ResetDropdownSize(ButtonName)
  625.     if RunService:IsClient() then
  626.         local p = game.Players.LocalPlayer
  627.         local TopbarFrame = p.PlayerGui:FindFirstChild("TopbarGUI")
  628.         if TopbarFrame then
  629.             local CheckLeft = TopbarFrame.TopbarFrame.Left:FindFirstChild(ButtonName)
  630.             local CheckRight = TopbarFrame.TopbarFrame.Right:FindFirstChild(ButtonName)
  631.             local Button = nil
  632.             if CheckLeft then
  633.                 Button = CheckLeft
  634.             elseif CheckRight then
  635.                 Button = CheckRight
  636.             end
  637.             if Button then
  638.                 Button.Dropdown.Size = UDim2.new(0,0,0,0)
  639.                 for _,o in pairs(Button.Dropdown:GetChildren()) do
  640.                     if o.ClassName == "TextButton" then
  641.                         Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset,0,Button.Dropdown.Size.Y.Offset + 25)
  642.                         wait()
  643.                         if o.TextFits == false then
  644.                             repeat
  645.                                 Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 1,0,Button.Dropdown.Size.Y.Offset)
  646.                                 wait()
  647.                             until o.TextFits == true
  648.                             Button.Dropdown.Size = UDim2.new(0,Button.Dropdown.Size.X.Offset + 8,0,Button.Dropdown.Size.Y.Offset)
  649.                             wait()
  650.                         end
  651.                     end
  652.                 end
  653.                 wait()
  654.                 return true
  655.             else
  656.                 return false
  657.             end
  658.         else
  659.             return false
  660.         end
  661.     end
  662. end
  663.  
  664. local module = TopbarModule
  665. module:Add("Test", "54479711", true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement