-- Cool Modular GUI + Modules in one file local Players = game:GetService("Players") local RunService = game:GetService("RunService") local LocalPlayer = Players.LocalPlayer local UserInputService = game:GetService("UserInputService") local camera = workspace.CurrentCamera -- Simple GUI Library local Library = {} Library.__index = Library function Library:CreateWindow(title, gradientType) local screenGui = Instance.new("ScreenGui") screenGui.Name = "CoolGUIHub" screenGui.ResetOnSpawn = false screenGui.Parent = game:GetService("CoreGui") local frame = Instance.new("Frame") frame.Size = UDim2.new(0, 400, 0, 500) frame.Position = UDim2.new(0.5, -200, 0.5, -250) frame.BackgroundColor3 = Color3.new(0, 0, 0) frame.BackgroundTransparency = 0 frame.BorderSizePixel = 0 frame.Parent = screenGui frame.ClipsDescendants = true -- Add UICorner to frame local uicorner = Instance.new("UICorner") uicorner.CornerRadius = UDim.new(0, 8) uicorner.Parent = frame -- Gradient background local bgGradient = Instance.new("UIGradient") bgGradient.Parent = frame bgGradient.Rotation = 90 local gradients = { ["Red & Black"] = { ColorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(255,0,0)), ColorSequenceKeypoint.new(1, Color3.fromRGB(0,0,0))}, TransparencySequence = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 0.6)}, Rotation = 180 }, ["Blue & Black"] = { ColorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(0,85,255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(0,0,0))}, TransparencySequence = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 0.7)}, Rotation = 180 }, ["Purple & Black"] = { ColorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(170,0,255)), ColorSequenceKeypoint.new(1, Color3.fromRGB(0,0,0))}, TransparencySequence = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 0.6)}, Rotation = 180 }, ["Green & Black"] = { ColorSequence = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(0,255,85)), ColorSequenceKeypoint.new(1, Color3.fromRGB(0,0,0))}, TransparencySequence = NumberSequence.new{NumberSequenceKeypoint.new(0, 0), NumberSequenceKeypoint.new(1, 0.7)}, Rotation = 180 } } local chosenGradient = gradients[gradientType] or gradients["Red & Black"] bgGradient.Color = chosenGradient.ColorSequence bgGradient.Transparency = chosenGradient.TransparencySequence bgGradient.Rotation = chosenGradient.Rotation -- Title bar local titleBar = Instance.new("Frame") titleBar.Size = UDim2.new(1, 0, 0, 40) titleBar.BackgroundTransparency = 1 titleBar.Parent = frame -- Add UICorner to titleBar for smooth edges local titleBarCorner = Instance.new("UICorner") titleBarCorner.CornerRadius = UDim.new(0, 8) titleBarCorner.Parent = titleBar local titleLabel = Instance.new("TextLabel") titleLabel.Text = title or "Cool GUI Hub" titleLabel.Size = UDim2.new(1, -40, 1, 0) titleLabel.Position = UDim2.new(0, 10, 0, 0) titleLabel.BackgroundTransparency = 1 titleLabel.TextColor3 = Color3.new(1,1,1) titleLabel.TextXAlignment = Enum.TextXAlignment.Left titleLabel.Font = Enum.Font.GothamBold titleLabel.TextSize = 20 titleLabel.Parent = titleBar -- Close button local closeButton = Instance.new("TextButton") closeButton.Text = "X" closeButton.Size = UDim2.new(0, 30, 0, 30) closeButton.Position = UDim2.new(1, -35, 0, 5) closeButton.BackgroundColor3 = Color3.fromRGB(255, 50, 50) closeButton.TextColor3 = Color3.new(1,1,1) closeButton.Font = Enum.Font.GothamBold closeButton.TextSize = 18 closeButton.Parent = titleBar closeButton.AutoButtonColor = true closeButton.MouseButton1Click:Connect(function() screenGui:Destroy() end) -- Container for controls local content = Instance.new("ScrollingFrame") content.Size = UDim2.new(1, -20, 1, -50) content.Position = UDim2.new(0, 10, 0, 45) content.BackgroundTransparency = 1 content.ScrollBarThickness = 5 content.Parent = frame -- UIListLayout for stacking controls local layout = Instance.new("UIListLayout") layout.Parent = content layout.SortOrder = Enum.SortOrder.LayoutOrder layout.Padding = UDim.new(0, 8) -- Store last added control to handle size self._content = content self._layout = layout self._screenGui = screenGui self._controlsCount = 0 -- Helper to add new controls and update canvas size function self:AddControl(control) control.Parent = content self._controlsCount = self._controlsCount + 1 content.CanvasSize = UDim2.new(0, 0, 0, layout.AbsoluteContentSize.Y + 20) end -- === DRAG LOGIC START === local dragging = false local dragInput = nil local dragStart = nil local startPos = nil local function clampPosition(pos, size) local viewportSize = camera.ViewportSize local x = math.clamp(pos.X, 0, viewportSize.X - size.X) local y = math.clamp(pos.Y, 0, viewportSize.Y - size.Y) return Vector2.new(x, y) end titleBar.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then dragging = true dragInput = input dragStart = input.Position startPos = frame.AbsolutePosition input.Changed:Connect(function() if input.UserInputState == Enum.UserInputState.End then dragging = false dragInput = nil end end) end end) titleBar.InputChanged:Connect(function(input) if input == dragInput then -- handled in UserInputService.InputChanged below end end) UserInputService.InputChanged:Connect(function(input) if input == dragInput and dragging then local delta = input.Position - dragStart local newPos = startPos + delta -- Clamp position so frame stays inside screen local clampedPos = clampPosition(newPos, frame.AbsoluteSize) local viewportSize = camera.ViewportSize local posX = clampedPos.X / viewportSize.X local posY = clampedPos.Y / viewportSize.Y frame.Position = UDim2.new(posX, 0, posY, 0) end end) -- === DRAG LOGIC END === return self end function Library:AddLabel(text) local label = Instance.new("TextLabel") label.Text = text or "Label" label.Size = UDim2.new(1, 0, 0, 25) label.BackgroundTransparency = 1 label.TextColor3 = Color3.new(1,1,1) label.Font = Enum.Font.Gotham label.TextSize = 18 label.TextXAlignment = Enum.TextXAlignment.Left self:AddControl(label) return label end function Library:AddToggle(text, callback) local frame = Instance.new("Frame") frame.Size = UDim2.new(1, 0, 0, 30) frame.BackgroundTransparency = 1 local label = Instance.new("TextLabel") label.Text = text label.Size = UDim2.new(1, -40, 1, 0) label.BackgroundTransparency = 1 label.TextColor3 = Color3.new(1,1,1) label.Font = Enum.Font.Gotham label.TextSize = 18 label.TextXAlignment = Enum.TextXAlignment.Left label.Parent = frame local toggle = Instance.new("TextButton") toggle.Text = "OFF" toggle.Size = UDim2.new(0, 40, 1, 0) toggle.Position = UDim2.new(1, -40, 0, 0) toggle.BackgroundColor3 = Color3.fromRGB(180, 0, 0) toggle.TextColor3 = Color3.new(1,1,1) toggle.Font = Enum.Font.GothamBold toggle.TextSize = 16 toggle.Parent = frame local enabled = false toggle.MouseButton1Click:Connect(function() enabled = not enabled if enabled then toggle.Text = "ON" toggle.BackgroundColor3 = Color3.fromRGB(0, 180, 0) else toggle.Text = "OFF" toggle.BackgroundColor3 = Color3.fromRGB(180, 0, 0) end if callback then callback(enabled) end end) self:AddControl(frame) return frame end -- Usage Example: local myGui = setmetatable({}, Library):CreateWindow("My Cool GUI", "Purple & Black") myGui:AddLabel("Welcome to the GUI!") myGui:AddToggle("Enable Feature", function(state) print("Toggle state:", state) end) return Library