Advertisement
timmie140

BSS library

Nov 27th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.86 KB | None | 0 0
  1. local Library = {}
  2. local Folder = game.ServerStorage:WaitForChild("UIComponents")
  3. local UserInputService = game:GetService("UserInputService")
  4. local RunService = game:GetService("RunService")
  5. local Screen = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
  6. local Config = { Color = Color3.fromRGB(0, 120, 255) }
  7.  
  8. local function LoadAsset(assetId)
  9.     local success, asset = pcall(function()
  10.         return Folder:FindFirstChild(assetId):Clone()
  11.     end)
  12.     if not success then
  13.         warn("Failed to load asset with ID:", assetId)
  14.         return nil
  15.     end
  16.     return asset
  17. end
  18.  
  19. function Library:CreateWindow(Name)
  20.     local WindowInit = {}
  21.     local Window = LoadAsset("Window")
  22.  
  23.     if not Window then return end
  24.  
  25.     Window.Name = Name .. " W"
  26.     Window.Parent = Screen
  27.     Window.Title.Text = Name
  28.  
  29.     function WindowInit:CreateTab(Name)
  30.         local TabInit = {}
  31.         local Tab = LoadAsset("Tab")
  32.  
  33.         if not Tab then return end
  34.  
  35.         Tab.Name = Name .. " T"
  36.         Tab.Parent = Window
  37.  
  38.         function TabInit:CreateSection(Name)
  39.             local SectionInit = {}
  40.             local Section = LoadAsset("Section")
  41.  
  42.             if not Section then return end
  43.  
  44.             Section.Name = Name .. " S"
  45.             Section.Parent = Tab
  46.  
  47.             function SectionInit:CreateTextBox(Name, PlaceHolder, NumbersOnly, Callback)
  48.                 local TextBoxInit = {}
  49.                 local TextBox = LoadAsset("TextBox")
  50.  
  51.                 if not TextBox then return end
  52.  
  53.                 TextBox.Name = Name .. " T"
  54.                 TextBox.Parent = Section.Container
  55.                 TextBox.Title.Text = Name
  56.                 TextBox.Background.Input.PlaceholderText = PlaceHolder
  57.                 TextBox.Title.Size = UDim2.new(1, 0, 0, TextBox.Title.TextBounds.Y + 5)
  58.                 TextBox.Size = UDim2.new(1, -10, 0, TextBox.Title.TextBounds.Y + 25)
  59.  
  60.                 TextBox.Background.Input.FocusLost:Connect(function()
  61.                     if NumbersOnly and not tonumber(TextBox.Background.Input.Text) then
  62.                         Callback(nil)
  63.                     else
  64.                         Callback(TextBox.Background.Input.Text)
  65.                     end
  66.                 end)
  67.  
  68.                 function TextBoxInit:SetValue(String)
  69.                     TextBox.Background.Input.Text = String
  70.                     Callback(String)
  71.                 end
  72.  
  73.                 function TextBoxInit:AddToolTip(Name)
  74.                     if Name:gsub(" ", "") ~= "" then
  75.                         TextBox.MouseEnter:Connect(function()
  76.                             Screen.ToolTip.Text = Name
  77.                             Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
  78.                             Screen.ToolTip.Visible = true
  79.                         end)
  80.                         TextBox.MouseLeave:Connect(function()
  81.                             Screen.ToolTip.Visible = false
  82.                         end)
  83.                     end
  84.                 end
  85.  
  86.                 return TextBoxInit
  87.             end
  88.  
  89.             function SectionInit:CreateToggle(Name, Default, Callback)
  90.                 local ToggleInit = {}
  91.                 local Toggle = LoadAsset("Toggle")
  92.  
  93.                 if not Toggle then return end
  94.  
  95.                 Toggle.Name = Name .. " T"
  96.                 Toggle.Parent = Section.Container
  97.                 Toggle.Title.Text = Name
  98.                 Toggle.Size = UDim2.new(1, -10, 0, Toggle.Title.TextBounds.Y + 5)
  99.  
  100.                 local ToggleState = Default or false
  101.                 local function SetState(State)
  102.                     Toggle.Toggle.BackgroundColor3 = State and Config.Color or Color3.fromRGB(50, 50, 50)
  103.                     ToggleState = State
  104.                     Callback(State)
  105.                 end
  106.  
  107.                 Toggle.MouseButton1Click:Connect(function()
  108.                     ToggleState = not ToggleState
  109.                     SetState(ToggleState)
  110.                 end)
  111.  
  112.                 function ToggleInit:AddToolTip(Name)
  113.                     if Name:gsub(" ", "") ~= "" then
  114.                         Toggle.MouseEnter:Connect(function()
  115.                             Screen.ToolTip.Text = Name
  116.                             Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
  117.                             Screen.ToolTip.Visible = true
  118.                         end)
  119.                         Toggle.MouseLeave:Connect(function()
  120.                             Screen.ToolTip.Visible = false
  121.                         end)
  122.                     end
  123.                 end
  124.  
  125.                 function ToggleInit:SetState(State)
  126.                     SetState(State)
  127.                 end
  128.  
  129.                 function ToggleInit:GetState()
  130.                     return ToggleState
  131.                 end
  132.  
  133.                 function ToggleInit:CreateKeybind(Bind, Callback)
  134.                     local KeybindInit = {}
  135.                     Bind = Bind or "NONE"
  136.  
  137.                     local WaitingForBind = false
  138.                     local Selected = Bind
  139.                     local Blacklist = {"W", "A", "S", "D", "Slash", "Tab", "Backspace", "Escape", "Space", "Delete", "Unknown", "Backquote"}
  140.  
  141.                     Toggle.Keybind.Visible = true
  142.                     Toggle.Keybind.Text = "[ " .. Bind .. " ]"
  143.  
  144.                     Toggle.Keybind.MouseButton1Click:Connect(function()
  145.                         Toggle.Keybind.Text = "[ ... ]"
  146.                         WaitingForBind = true
  147.                     end)
  148.  
  149.                     Toggle.Keybind:GetPropertyChangedSignal("TextBounds"):Connect(function()
  150.                         Toggle.Keybind.Size = UDim2.new(0, Toggle.Keybind.TextBounds.X, 1, 0)
  151.                         Toggle.Title.Size = UDim2.new(1, -Toggle.Keybind.Size.X.Offset - 15, 1, 0)
  152.                     end)
  153.  
  154.                     UserInputService.InputBegan:Connect(function(Input)
  155.                         if WaitingForBind and Input.UserInputType == Enum.UserInputType.Keyboard then
  156.                             local Key = tostring(Input.KeyCode):gsub("Enum.KeyCode.", "")
  157.                             if not table.find(Blacklist, Key) then
  158.                                 Toggle.Keybind.Text = "[ " .. Key .. " ]"
  159.                                 Selected = Key
  160.                             else
  161.                                 Toggle.Keybind.Text = "[ NONE ]"
  162.                                 Selected = "NONE"
  163.                             end
  164.                             WaitingForBind = false
  165.                         elseif Input.UserInputType == Enum.UserInputType.Keyboard then
  166.                             local Key = tostring(Input.KeyCode):gsub("Enum.KeyCode.", "")
  167.                             if Key == Selected then
  168.                                 ToggleState = not ToggleState
  169.                                 SetState(ToggleState)
  170.                                 if Callback then
  171.                                     Callback(Key)
  172.                                 end
  173.                             end
  174.                         end
  175.                     end)
  176.  
  177.                     function KeybindInit:SetBind(Key)
  178.                         Toggle.Keybind.Text = "[ " .. Key .. " ]"
  179.                         Selected = Key
  180.                     end
  181.  
  182.                     function KeybindInit:GetBind()
  183.                         return Selected
  184.                     end
  185.  
  186.                     return KeybindInit
  187.                 end
  188.  
  189.                 return ToggleInit
  190.             end
  191.  
  192.             function SectionInit:CreateSlider(Name, Min, Max, Default, Precise, Callback)
  193.                 local SliderInit = {}
  194.                 local Slider = LoadAsset("Slider")
  195.  
  196.                 if not Slider then return end
  197.  
  198.                 Slider.Name = Name .. " S"
  199.                 Slider.Parent = Section.Container
  200.                 Slider.Title.Text = Name
  201.                 Slider.Slider.Bar.Size = UDim2.new(Min / Max, 0, 1, 0)
  202.                 Slider.Slider.Bar.BackgroundColor3 = Config.Color
  203.                 Slider.Value.PlaceholderText = tostring(Min)
  204.                 Slider.Title.Size = UDim2.new(1, 0, 0, Slider.Title.TextBounds.Y + 5)
  205.                 Slider.Size = UDim2.new(1, -10, 0, Slider.Title.TextBounds.Y + 15)
  206.  
  207.                 local GlobalSliderValue = Default or 50
  208.                 local Dragging = false
  209.  
  210.                 local function Sliding(Input)
  211.                     local Position = UDim2.new(math.clamp((Input.Position.X - Slider.Slider.AbsolutePosition.X) / Slider.Slider.AbsoluteSize.X, 0, 1), 0, 1, 0)
  212.                     Slider.Slider.Bar.Size = Position
  213.                     local SliderValue = Precise and Position.X.Scale * (Max - Min) + Min or math.floor(Position.X.Scale * (Max - Min) + Min)
  214.                     SliderValue = tonumber(string.format("%.2f", SliderValue))
  215.                     GlobalSliderValue = SliderValue
  216.                     Slider.Value.PlaceholderText = tostring(SliderValue)
  217.                     Callback(GlobalSliderValue)
  218.                 end
  219.  
  220.                 local function SetValue(Value)
  221.                     GlobalSliderValue = Value
  222.                     Slider.Slider.Bar.Size = UDim2.new(Value / Max, 0, 1, 0)
  223.                     Slider.Value.PlaceholderText = tostring(Value)
  224.                     Callback(Value)
  225.                 end
  226.  
  227.                 Slider.Value.FocusLost:Connect(function()
  228.                     local Value = tonumber(Slider.Value.Text)
  229.                     if not Value then
  230.                         Slider.Value.Text = tostring(GlobalSliderValue)
  231.                     elseif Value < Min then
  232.                         Slider.Value.Text = tostring(Min)
  233.                     elseif Value > Max then
  234.                         Slider.Value.Text = tostring(Max)
  235.                     end
  236.  
  237.                     GlobalSliderValue = tonumber(Slider.Value.Text)
  238.                     Slider.Slider.Bar.Size = UDim2.new(GlobalSliderValue / Max, 0, 1, 0)
  239.                     Callback(GlobalSliderValue)
  240.                     Slider.Value.Text = ""
  241.                 end)
  242.  
  243.                 Slider.InputBegan:Connect(function(Input)
  244.                     if Input.UserInputType == Enum.UserInputType.MouseButton1 then
  245.                         Sliding(Input)
  246.                         Dragging = true
  247.                     end
  248.                 end)
  249.  
  250.                 Slider.InputEnded:Connect(function(Input)
  251.                     if Input.UserInputType == Enum.UserInputType.MouseButton1 then
  252.                         Dragging = false
  253.                     end
  254.                 end)
  255.  
  256.                 RunService.RenderStepped:Connect(function()
  257.                     if Dragging then
  258.                         local MousePosition = UserInputService:GetMouseLocation()
  259.                         Sliding({Position = MousePosition})
  260.                     end
  261.                 end)
  262.  
  263.                 function SliderInit:AddToolTip(Name)
  264.                     if Name:gsub(" ", "") ~= "" then
  265.                         Slider.MouseEnter:Connect(function()
  266.                             Screen.ToolTip.Text = Name
  267.                             Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
  268.                             Screen.ToolTip.Visible = true
  269.                         end)
  270.                         Slider.MouseLeave:Connect(function()
  271.                             Screen.ToolTip.Visible = false
  272.                         end)
  273.                     end
  274.                 end
  275.  
  276.                 function SliderInit:SetValue(Value)
  277.                     SetValue(Value)
  278.                 end
  279.  
  280.                 function SliderInit:GetValue()
  281.                     return GlobalSliderValue
  282.                 end
  283.  
  284.                 return SliderInit
  285.             end
  286.  
  287.             return SectionInit
  288.         end
  289.  
  290.         return TabInit
  291.     end
  292.  
  293.     return WindowInit
  294. end
  295.  
  296. return Library
  297.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement