Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local gui = nil
- local mainFrame = nil
- local closeButton = nil
- -- Function to create the GUI
- local function createGui()
- -- Check if GUI already exists and destroy it
- if gui then
- gui:Destroy()
- end
- local ScreenGui = Instance.new("ScreenGui")
- local MainFrame = Instance.new("Frame")
- local CloseButton = Instance.new("TextButton")
- -- Set up ScreenGui
- ScreenGui.Name = "PersistentGUI"
- ScreenGui.ResetOnSpawn = false
- ScreenGui.Parent = player.PlayerGui
- -- Set up CloseButton
- CloseButton.Size = UDim2.new(0, 100, 0, 25)
- CloseButton.Position = UDim2.new(0.5, -50, 0, 10)
- CloseButton.BackgroundColor3 = Color3.fromRGB(100, 100, 100)
- CloseButton.Text = "Close"
- CloseButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- CloseButton.Font = Enum.Font.SourceSansBold
- CloseButton.TextSize = 14
- CloseButton.Parent = ScreenGui
- CloseButton.ZIndex = 10
- -- Set up MainFrame
- MainFrame.Size = UDim2.new(0.2, 0, 0.6, 0)
- MainFrame.Position = UDim2.new(0.5, -MainFrame.Size.X.Scale * 500, 0, 80) -- Increased Y offset to 80
- MainFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
- MainFrame.BackgroundTransparency = 0.5
- MainFrame.BorderSizePixel = 0
- MainFrame.ClipsDescendants = true
- MainFrame.Visible = true
- MainFrame.ZIndex = 1
- MainFrame.Parent = ScreenGui
- -- Create list layout for buttons
- local UIListLayout = Instance.new("UIListLayout")
- UIListLayout.Parent = MainFrame
- UIListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
- UIListLayout.Padding = UDim.new(0, 20)
- UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder
- -- Function to create toggle buttons
- local function createToggleButton(number)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.7, 0, 0, 30)
- button.BackgroundColor3 = Color3.fromRGB(0, 0, 0) -- Start with black
- button.Text = "Function " .. number
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Font = Enum.Font.SourceSansBold
- button.TextSize = 14
- button.LayoutOrder = number
- button.Parent = MainFrame
- button.ZIndex = 2
- -- Add rounded corners to button
- local corner = Instance.new("UICorner")
- corner.CornerRadius = UDim.new(0.3, 0)
- corner.Parent = button
- -- Toggle state
- local isEnabled = false
- button.MouseButton1Click:Connect(function()
- isEnabled = not isEnabled
- if isEnabled then
- button.BackgroundColor3 = Color3.fromRGB(0, 0, 255) -- Blue when enabled
- else
- button.BackgroundColor3 = Color3.fromRGB(0, 0, 0) -- Black when disabled
- end
- -- Add your function logic here for each button
- end)
- return button
- end
- -- Create 5 buttons
- for i = 1, 5 do
- createToggleButton(i)
- end
- -- Add padding at the top of the frame
- local UIPadding = Instance.new("UIPadding")
- UIPadding.Parent = MainFrame
- UIPadding.PaddingTop = UDim.new(0, 20)
- -- Rounded corners for MainFrame
- local cornerFrame = Instance.new("UICorner")
- cornerFrame.CornerRadius = UDim.new(0.05, 0)
- cornerFrame.Parent = MainFrame
- -- Rounded corners for CloseButton
- local cornerButton = Instance.new("UICorner")
- cornerButton.CornerRadius = UDim.new(0.3, 0)
- cornerButton.Parent = CloseButton
- -- Store references to GUI elements
- gui = ScreenGui
- mainFrame = MainFrame
- closeButton = CloseButton
- -- Function to update MainFrame position relative to CloseButton
- local function updateMainFramePosition()
- local buttonCenterX = CloseButton.AbsolutePosition.X + (CloseButton.AbsoluteSize.X / 2)
- local mainFrameHalfWidth = (MainFrame.Size.X.Scale * ScreenGui.AbsoluteSize.X) / 2
- MainFrame.Position = UDim2.new(0, buttonCenterX - mainFrameHalfWidth, 0, CloseButton.AbsolutePosition.Y + 80) -- Increased offset
- end
- -- Function to toggle GUI visibility
- local function toggleCloseButton()
- MainFrame.Visible = not MainFrame.Visible
- CloseButton.Text = MainFrame.Visible and "Close" or "Open"
- if MainFrame.Visible then
- updateMainFramePosition()
- end
- end
- -- Make both CloseButton and MainFrame draggable
- local function makeDraggable(gui)
- local dragging = false
- local dragStart = nil
- local startPos = nil
- local dragInput = nil
- local startPos = nil
- gui.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- dragging = true
- dragStart = input.Position
- startPos = gui.Position
- input.Changed:Connect(function()
- if input.UserInputState == Enum.UserInputState.End then
- dragging = false
- end
- end)
- end
- end)
- gui.InputChanged:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
- dragInput = input
- end
- end)
- game:GetService("UserInputService").InputChanged:Connect(function(input)
- if input == dragInput and dragging then
- local delta = input.Position - dragStart
- if gui == CloseButton then
- local newY = math.clamp(startPos.Y.Offset + delta.Y, 10, 50)
- gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, 0, newY)
- if MainFrame.Visible then
- updateMainFramePosition()
- end
- else
- gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X,
- startPos.Y.Scale, startPos.Y.Offset + delta.Y)
- end
- end
- end)
- end
- -- Make both elements draggable
- makeDraggable(CloseButton)
- makeDraggable(MainFrame)
- -- Connect toggle function
- CloseButton.MouseButton1Click:Connect(toggleCloseButton)
- -- Initial position update
- updateMainFramePosition()
- -- Handle window resize
- game:GetService("RunService").RenderStepped:Connect(function()
- if MainFrame.Visible then
- updateMainFramePosition()
- end
- end)
- end
- -- Create initial GUI
- createGui()
- -- Handle character respawning
- player.CharacterAdded:Connect(function()
- if not gui or not gui.Parent then
- createGui()
- end
- end)
- -- Handle player removal
- player.AncestryChanged:Connect(function(_, parent)
- if not parent then
- gui:Destroy()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement