imaRapguy

Untitled

Sep 13th, 2024
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.34 KB | None | 0 0
  1. -- Create ScreenGui
  2. local screenGui = Instance.new("ScreenGui")
  3. screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  4.  
  5. -- Create Toggle Button to Reopen GUI (Initially Hidden)
  6. local toggleButton = Instance.new("TextButton")
  7. toggleButton.Size = UDim2.new(0, 100, 0, 50)
  8. toggleButton.Position = UDim2.new(0, 10, 0, 10) -- Position in the top-left corner
  9. toggleButton.Text = "Open GUI"
  10. toggleButton.TextColor3 = Color3.new(1, 1, 1)
  11. toggleButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  12. toggleButton.BorderSizePixel = 2
  13. toggleButton.Visible = false -- Hidden by default
  14. toggleButton.Parent = screenGui
  15.  
  16. -- Variables to track GUI state
  17. local guiExists = true
  18.  
  19. -- Function to create the draggable teleport GUI
  20. local function createTeleportGui()
  21. -- Create Main Frame (Black GUI)
  22. local mainFrame = Instance.new("Frame")
  23. mainFrame.Size = UDim2.new(0, 250, 0, 100)
  24. mainFrame.Position = UDim2.new(0, 100, 0, 100)
  25. mainFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  26. mainFrame.BorderSizePixel = 2
  27. mainFrame.Draggable = true
  28. mainFrame.Active = true
  29. mainFrame.Parent = screenGui
  30.  
  31. -- Hide toggle button when GUI is created
  32. toggleButton.Visible = false
  33.  
  34. -- Create Close Button (X)
  35. local closeButton = Instance.new("TextButton")
  36. closeButton.Size = UDim2.new(0, 30, 0, 30)
  37. closeButton.Position = UDim2.new(0, 0, 0, 0)
  38. closeButton.Text = "X"
  39. closeButton.TextColor3 = Color3.new(1, 1, 1)
  40. closeButton.BackgroundColor3 = Color3.fromRGB(100, 0, 0)
  41. closeButton.BorderSizePixel = 1
  42. closeButton.Parent = mainFrame
  43.  
  44. -- Create Teleport Button
  45. local teleportButton = Instance.new("TextButton")
  46. teleportButton.Size = UDim2.new(0, 200, 0, 50)
  47. teleportButton.Position = UDim2.new(0, 25, 0, 40)
  48. teleportButton.Text = "Teleport to Lowest Health Player"
  49. teleportButton.TextColor3 = Color3.new(1, 1, 1)
  50. teleportButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  51. teleportButton.BorderSizePixel = 2
  52. teleportButton.Parent = mainFrame
  53.  
  54. -- Function to find the player with the lowest health
  55. local function findLowestHealthPlayer()
  56. local lowestHealthPlayer = nil
  57. local lowestHealth = math.huge
  58.  
  59. for _, player in pairs(game.Players:GetPlayers()) do
  60. if player.Character and player.Character:FindFirstChild("Humanoid") then
  61. local health = player.Character.Humanoid.Health
  62. if health > 0 and health < lowestHealth then
  63. lowestHealth = health
  64. lowestHealthPlayer = player
  65. end
  66. end
  67. end
  68.  
  69. return lowestHealthPlayer
  70. end
  71.  
  72. -- Teleport function
  73. local function teleportToLowestHealthPlayer()
  74. local lowestHealthPlayer = findLowestHealthPlayer()
  75.  
  76. if lowestHealthPlayer and lowestHealthPlayer.Character and game.Players.LocalPlayer.Character then
  77. local targetPosition = lowestHealthPlayer.Character.HumanoidRootPart.Position
  78. game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)
  79. else
  80. print("No valid player to teleport to.")
  81. end
  82. end
  83.  
  84. -- Connect button click to teleport function
  85. teleportButton.MouseButton1Click:Connect(teleportToLowestHealthPlayer)
  86.  
  87. -- Connect Close Button (X) to destroy GUI
  88. closeButton.MouseButton1Click:Connect(function()
  89. mainFrame:Destroy()
  90. guiExists = false
  91. toggleButton.Visible = true -- Show the toggle button when GUI is destroyed
  92. end)
  93.  
  94. -- Make the frame draggable on both PC and Mobile
  95. local function makeDraggable(frame)
  96. local dragging
  97. local dragInput
  98. local dragStart
  99. local startPos
  100.  
  101. local function update(input)
  102. local delta = input.Position - dragStart
  103. frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  104. end
  105.  
  106. frame.InputBegan:Connect(function(input)
  107. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  108. dragging = true
  109. dragStart = input.Position
  110. startPos = frame.Position
  111.  
  112. input.Changed:Connect(function()
  113. if input.UserInputState == Enum.UserInputState.End then
  114. dragging = false
  115. end
  116. end)
  117. end
  118. end)
  119.  
  120. frame.InputChanged:Connect(function(input)
  121. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  122. dragInput = input
  123. end
  124. end)
  125.  
  126. game:GetService("UserInputService").InputChanged:Connect(function(input)
  127. if input == dragInput and dragging then
  128. update(input)
  129. end
  130. end)
  131. end
  132.  
  133. -- Make the main frame draggable
  134. makeDraggable(mainFrame)
  135. end
  136.  
  137. -- Initial creation of the Teleport GUI
  138. createTeleportGui()
  139.  
  140. -- Function to reopen the GUI when the toggle button is clicked
  141. toggleButton.MouseButton1Click:Connect(function()
  142. if not guiExists then
  143. createTeleportGui()
  144. guiExists = true
  145. end
  146. end)
Advertisement
Add Comment
Please, Sign In to add comment