Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Library = {}
- local Folder = game.ServerStorage:WaitForChild("UIComponents")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Screen = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("ScreenGui")
- local Config = { Color = Color3.fromRGB(0, 120, 255) }
- local function LoadAsset(assetId)
- local success, asset = pcall(function()
- return Folder:FindFirstChild(assetId):Clone()
- end)
- if not success then
- warn("Failed to load asset with ID:", assetId)
- return nil
- end
- return asset
- end
- function Library:CreateWindow(Name)
- local WindowInit = {}
- local Window = LoadAsset("Window")
- if not Window then return end
- Window.Name = Name .. " W"
- Window.Parent = Screen
- Window.Title.Text = Name
- function WindowInit:CreateTab(Name)
- local TabInit = {}
- local Tab = LoadAsset("Tab")
- if not Tab then return end
- Tab.Name = Name .. " T"
- Tab.Parent = Window
- function TabInit:CreateSection(Name)
- local SectionInit = {}
- local Section = LoadAsset("Section")
- if not Section then return end
- Section.Name = Name .. " S"
- Section.Parent = Tab
- function SectionInit:CreateTextBox(Name, PlaceHolder, NumbersOnly, Callback)
- local TextBoxInit = {}
- local TextBox = LoadAsset("TextBox")
- if not TextBox then return end
- TextBox.Name = Name .. " T"
- TextBox.Parent = Section.Container
- TextBox.Title.Text = Name
- TextBox.Background.Input.PlaceholderText = PlaceHolder
- TextBox.Title.Size = UDim2.new(1, 0, 0, TextBox.Title.TextBounds.Y + 5)
- TextBox.Size = UDim2.new(1, -10, 0, TextBox.Title.TextBounds.Y + 25)
- TextBox.Background.Input.FocusLost:Connect(function()
- if NumbersOnly and not tonumber(TextBox.Background.Input.Text) then
- Callback(nil)
- else
- Callback(TextBox.Background.Input.Text)
- end
- end)
- function TextBoxInit:SetValue(String)
- TextBox.Background.Input.Text = String
- Callback(String)
- end
- function TextBoxInit:AddToolTip(Name)
- if Name:gsub(" ", "") ~= "" then
- TextBox.MouseEnter:Connect(function()
- Screen.ToolTip.Text = Name
- Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
- Screen.ToolTip.Visible = true
- end)
- TextBox.MouseLeave:Connect(function()
- Screen.ToolTip.Visible = false
- end)
- end
- end
- return TextBoxInit
- end
- function SectionInit:CreateToggle(Name, Default, Callback)
- local ToggleInit = {}
- local Toggle = LoadAsset("Toggle")
- if not Toggle then return end
- Toggle.Name = Name .. " T"
- Toggle.Parent = Section.Container
- Toggle.Title.Text = Name
- Toggle.Size = UDim2.new(1, -10, 0, Toggle.Title.TextBounds.Y + 5)
- local ToggleState = Default or false
- local function SetState(State)
- Toggle.Toggle.BackgroundColor3 = State and Config.Color or Color3.fromRGB(50, 50, 50)
- ToggleState = State
- Callback(State)
- end
- Toggle.MouseButton1Click:Connect(function()
- ToggleState = not ToggleState
- SetState(ToggleState)
- end)
- function ToggleInit:AddToolTip(Name)
- if Name:gsub(" ", "") ~= "" then
- Toggle.MouseEnter:Connect(function()
- Screen.ToolTip.Text = Name
- Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
- Screen.ToolTip.Visible = true
- end)
- Toggle.MouseLeave:Connect(function()
- Screen.ToolTip.Visible = false
- end)
- end
- end
- function ToggleInit:SetState(State)
- SetState(State)
- end
- function ToggleInit:GetState()
- return ToggleState
- end
- function ToggleInit:CreateKeybind(Bind, Callback)
- local KeybindInit = {}
- Bind = Bind or "NONE"
- local WaitingForBind = false
- local Selected = Bind
- local Blacklist = {"W", "A", "S", "D", "Slash", "Tab", "Backspace", "Escape", "Space", "Delete", "Unknown", "Backquote"}
- Toggle.Keybind.Visible = true
- Toggle.Keybind.Text = "[ " .. Bind .. " ]"
- Toggle.Keybind.MouseButton1Click:Connect(function()
- Toggle.Keybind.Text = "[ ... ]"
- WaitingForBind = true
- end)
- Toggle.Keybind:GetPropertyChangedSignal("TextBounds"):Connect(function()
- Toggle.Keybind.Size = UDim2.new(0, Toggle.Keybind.TextBounds.X, 1, 0)
- Toggle.Title.Size = UDim2.new(1, -Toggle.Keybind.Size.X.Offset - 15, 1, 0)
- end)
- UserInputService.InputBegan:Connect(function(Input)
- if WaitingForBind and Input.UserInputType == Enum.UserInputType.Keyboard then
- local Key = tostring(Input.KeyCode):gsub("Enum.KeyCode.", "")
- if not table.find(Blacklist, Key) then
- Toggle.Keybind.Text = "[ " .. Key .. " ]"
- Selected = Key
- else
- Toggle.Keybind.Text = "[ NONE ]"
- Selected = "NONE"
- end
- WaitingForBind = false
- elseif Input.UserInputType == Enum.UserInputType.Keyboard then
- local Key = tostring(Input.KeyCode):gsub("Enum.KeyCode.", "")
- if Key == Selected then
- ToggleState = not ToggleState
- SetState(ToggleState)
- if Callback then
- Callback(Key)
- end
- end
- end
- end)
- function KeybindInit:SetBind(Key)
- Toggle.Keybind.Text = "[ " .. Key .. " ]"
- Selected = Key
- end
- function KeybindInit:GetBind()
- return Selected
- end
- return KeybindInit
- end
- return ToggleInit
- end
- function SectionInit:CreateSlider(Name, Min, Max, Default, Precise, Callback)
- local SliderInit = {}
- local Slider = LoadAsset("Slider")
- if not Slider then return end
- Slider.Name = Name .. " S"
- Slider.Parent = Section.Container
- Slider.Title.Text = Name
- Slider.Slider.Bar.Size = UDim2.new(Min / Max, 0, 1, 0)
- Slider.Slider.Bar.BackgroundColor3 = Config.Color
- Slider.Value.PlaceholderText = tostring(Min)
- Slider.Title.Size = UDim2.new(1, 0, 0, Slider.Title.TextBounds.Y + 5)
- Slider.Size = UDim2.new(1, -10, 0, Slider.Title.TextBounds.Y + 15)
- local GlobalSliderValue = Default or 50
- local Dragging = false
- local function Sliding(Input)
- local Position = UDim2.new(math.clamp((Input.Position.X - Slider.Slider.AbsolutePosition.X) / Slider.Slider.AbsoluteSize.X, 0, 1), 0, 1, 0)
- Slider.Slider.Bar.Size = Position
- local SliderValue = Precise and Position.X.Scale * (Max - Min) + Min or math.floor(Position.X.Scale * (Max - Min) + Min)
- SliderValue = tonumber(string.format("%.2f", SliderValue))
- GlobalSliderValue = SliderValue
- Slider.Value.PlaceholderText = tostring(SliderValue)
- Callback(GlobalSliderValue)
- end
- local function SetValue(Value)
- GlobalSliderValue = Value
- Slider.Slider.Bar.Size = UDim2.new(Value / Max, 0, 1, 0)
- Slider.Value.PlaceholderText = tostring(Value)
- Callback(Value)
- end
- Slider.Value.FocusLost:Connect(function()
- local Value = tonumber(Slider.Value.Text)
- if not Value then
- Slider.Value.Text = tostring(GlobalSliderValue)
- elseif Value < Min then
- Slider.Value.Text = tostring(Min)
- elseif Value > Max then
- Slider.Value.Text = tostring(Max)
- end
- GlobalSliderValue = tonumber(Slider.Value.Text)
- Slider.Slider.Bar.Size = UDim2.new(GlobalSliderValue / Max, 0, 1, 0)
- Callback(GlobalSliderValue)
- Slider.Value.Text = ""
- end)
- Slider.InputBegan:Connect(function(Input)
- if Input.UserInputType == Enum.UserInputType.MouseButton1 then
- Sliding(Input)
- Dragging = true
- end
- end)
- Slider.InputEnded:Connect(function(Input)
- if Input.UserInputType == Enum.UserInputType.MouseButton1 then
- Dragging = false
- end
- end)
- RunService.RenderStepped:Connect(function()
- if Dragging then
- local MousePosition = UserInputService:GetMouseLocation()
- Sliding({Position = MousePosition})
- end
- end)
- function SliderInit:AddToolTip(Name)
- if Name:gsub(" ", "") ~= "" then
- Slider.MouseEnter:Connect(function()
- Screen.ToolTip.Text = Name
- Screen.ToolTip.Size = UDim2.new(0, Screen.ToolTip.TextBounds.X + 5, 0, Screen.ToolTip.TextBounds.Y + 5)
- Screen.ToolTip.Visible = true
- end)
- Slider.MouseLeave:Connect(function()
- Screen.ToolTip.Visible = false
- end)
- end
- end
- function SliderInit:SetValue(Value)
- SetValue(Value)
- end
- function SliderInit:GetValue()
- return GlobalSliderValue
- end
- return SliderInit
- end
- return SectionInit
- end
- return TabInit
- end
- return WindowInit
- end
- return Library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement