Run it
Copy the script and paste it into your executor.
-- 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 = .(, , , )
frame.Position = .(, -, , -)
frame.BackgroundColor3 = .(, , )
frame.BorderSizePixel =
title = .(, frame)
title.Size = .(, , , )
title.BackgroundColor3 = .(, , )
title.Text =
title.TextColor3 = .(, , )
title.Font = .Font.SourceSansBold
title.TextSize =
dragging =
dragInput, dragStart, startPos
title.InputBegan:((input)
input.UserInputType == .UserInputType.MouseButton1
dragging =
dragStart = input.Position
startPos = frame.Position
)
title.InputEnded:((input)
input.UserInputType == .UserInputType.MouseButton1
dragging =
)
UIS.InputChanged:((input)
dragging input.UserInputType == .UserInputType.MouseMovement
delta = input.Position - dragStart
newPos = .(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
screenSize = .CurrentCamera.ViewportSize
maxX = screenSize.X - frame.AbsoluteSize.X
maxY = screenSize.Y - frame.AbsoluteSize.Y
newPos = .(, .(newPos.X.Offset, , maxX), , .(newPos.Y.Offset, , maxY))
frame.Position = newPos
)Admin

Universal