-- Draggable GUI that stays within the screen bounds local Players = game:GetService("Players") local UIS = game:GetService("UserInputService") local player = Players.LocalPlayer local gui = Instance.new("ScreenGui", game.CoreGui) gui.Name = "BoundedDraggableGUI" gui.ResetOnSpawn = false gui.IgnoreGuiInset = true -- Main draggable frame local frame = Instance.new("Frame", gui) frame.Size = UDim2.new(0, 300, 0, 150) frame.Position = UDim2.new(0.5, -150, 0.5, -75) frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40) frame.BorderSizePixel = 0 -- Add a title bar to drag from local title = Instance.new("TextLabel", frame) title.Size = UDim2.new(1, 0, 0, 30) title.BackgroundColor3 = Color3.fromRGB(60, 60, 60) title.Text = "Drag Me (Locked to Screen)" title.TextColor3 = Color3.fromRGB(255, 255, 255) title.Font = Enum.Font.SourceSansBold title.TextSize = 18 -- Make frame draggable (within screen bounds) local dragging = false local dragInput, dragStart, startPos title.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then dragging = true dragStart = input.Position startPos = frame.Position end end) title.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then dragging = false end end) UIS.InputChanged:Connect(function(input) if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then local delta = input.Position - dragStart local newPos = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y) -- Clamp to screen local screenSize = workspace.CurrentCamera.ViewportSize local maxX = screenSize.X - frame.AbsoluteSize.X local maxY = screenSize.Y - frame.AbsoluteSize.Y newPos = UDim2.new(0, math.clamp(newPos.X.Offset, 0, maxX), 0, math.clamp(newPos.Y.Offset, 0, maxY)) frame.Position = newPos end end)