Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create ScreenGui
- local screenGui = Instance.new("ScreenGui")
- screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- -- Create Toggle Button to Reopen GUI (Initially Hidden)
- local toggleButton = Instance.new("TextButton")
- toggleButton.Size = UDim2.new(0, 100, 0, 50)
- toggleButton.Position = UDim2.new(0, 10, 0, 10) -- Position in the top-left corner
- toggleButton.Text = "Open GUI"
- toggleButton.TextColor3 = Color3.new(1, 1, 1)
- toggleButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- toggleButton.BorderSizePixel = 2
- toggleButton.Visible = false -- Hidden by default
- toggleButton.Parent = screenGui
- -- Variables to track GUI state
- local guiExists = true
- -- Function to create the draggable teleport GUI
- local function createTeleportGui()
- -- Create Main Frame (Black GUI)
- local mainFrame = Instance.new("Frame")
- mainFrame.Size = UDim2.new(0, 250, 0, 100)
- mainFrame.Position = UDim2.new(0, 100, 0, 100)
- mainFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- mainFrame.BorderSizePixel = 2
- mainFrame.Draggable = true
- mainFrame.Active = true
- mainFrame.Parent = screenGui
- -- Hide toggle button when GUI is created
- toggleButton.Visible = false
- -- Create Close Button (X)
- local closeButton = Instance.new("TextButton")
- closeButton.Size = UDim2.new(0, 30, 0, 30)
- closeButton.Position = UDim2.new(0, 0, 0, 0)
- closeButton.Text = "X"
- closeButton.TextColor3 = Color3.new(1, 1, 1)
- closeButton.BackgroundColor3 = Color3.fromRGB(100, 0, 0)
- closeButton.BorderSizePixel = 1
- closeButton.Parent = mainFrame
- -- Create Teleport Button
- local teleportButton = Instance.new("TextButton")
- teleportButton.Size = UDim2.new(0, 200, 0, 50)
- teleportButton.Position = UDim2.new(0, 25, 0, 40)
- teleportButton.Text = "Teleport to Lowest Health Player"
- teleportButton.TextColor3 = Color3.new(1, 1, 1)
- teleportButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- teleportButton.BorderSizePixel = 2
- teleportButton.Parent = mainFrame
- -- Function to find the player with the lowest health
- local function findLowestHealthPlayer()
- local lowestHealthPlayer = nil
- local lowestHealth = math.huge
- for _, player in pairs(game.Players:GetPlayers()) do
- if player.Character and player.Character:FindFirstChild("Humanoid") then
- local health = player.Character.Humanoid.Health
- if health > 0 and health < lowestHealth then
- lowestHealth = health
- lowestHealthPlayer = player
- end
- end
- end
- return lowestHealthPlayer
- end
- -- Teleport function
- local function teleportToLowestHealthPlayer()
- local lowestHealthPlayer = findLowestHealthPlayer()
- if lowestHealthPlayer and lowestHealthPlayer.Character and game.Players.LocalPlayer.Character then
- local targetPosition = lowestHealthPlayer.Character.HumanoidRootPart.Position
- game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)
- else
- print("No valid player to teleport to.")
- end
- end
- -- Connect button click to teleport function
- teleportButton.MouseButton1Click:Connect(teleportToLowestHealthPlayer)
- -- Connect Close Button (X) to destroy GUI
- closeButton.MouseButton1Click:Connect(function()
- mainFrame:Destroy()
- guiExists = false
- toggleButton.Visible = true -- Show the toggle button when GUI is destroyed
- end)
- -- Make the frame draggable on both PC and Mobile
- local function makeDraggable(frame)
- local dragging
- local dragInput
- local dragStart
- local startPos
- local function update(input)
- local delta = input.Position - dragStart
- frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
- end
- frame.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
- dragging = true
- dragStart = input.Position
- startPos = frame.Position
- input.Changed:Connect(function()
- if input.UserInputState == Enum.UserInputState.End then
- dragging = false
- end
- end)
- end
- end)
- frame.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
- update(input)
- end
- end)
- end
- -- Make the main frame draggable
- makeDraggable(mainFrame)
- end
- -- Initial creation of the Teleport GUI
- createTeleportGui()
- -- Function to reopen the GUI when the toggle button is clicked
- toggleButton.MouseButton1Click:Connect(function()
- if not guiExists then
- createTeleportGui()
- guiExists = true
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment