MaxproGlitcher

Gui teleport player

Oct 24th, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. -- LocalScript to display all players in the game, teleport to them, with scrollable player list, exit, and open buttons
  2.  
  3. local Players = game:GetService("Players")
  4. local player = Players.LocalPlayer
  5. local playerGui = player:WaitForChild("PlayerGui")
  6.  
  7. -- Create a ScreenGui for the player list
  8. local screenGui = Instance.new("ScreenGui")
  9. screenGui.Parent = playerGui
  10.  
  11. -- Create a ScrollingFrame to hold the player usernames (scrollable frame)
  12. local userFrame = Instance.new("ScrollingFrame")
  13. userFrame.Size = UDim2.new(0, 300, 0, 400)
  14. userFrame.Position = UDim2.new(0.5, -150, 0.5, -200)
  15. userFrame.BackgroundColor3 = Color3.fromRGB(0, 0, 0) -- Black background
  16. userFrame.BackgroundTransparency = 0.5 -- Semi-transparent background
  17. userFrame.BorderSizePixel = 0 -- No border
  18. userFrame.ScrollBarThickness = 10 -- Thickness of the scrollbar
  19. userFrame.Visible = true
  20. userFrame.Parent = screenGui
  21. userFrame.CanvasSize = UDim2.new(0, 0, 0, 0) -- We'll adjust this dynamically
  22.  
  23. -- Create a UIListLayout to arrange player usernames vertically in the scrollable frame
  24. local listLayout = Instance.new("UIListLayout")
  25. listLayout.Parent = userFrame
  26.  
  27. -- Function to populate usernames
  28. local function populateUsernames()
  29. -- Clear any existing buttons before populating
  30. for _, child in ipairs(userFrame:GetChildren()) do
  31. if child:IsA("TextButton") then
  32. child:Destroy()
  33. end
  34. end
  35.  
  36. -- Create a button for each player
  37. for _, otherPlayer in ipairs(Players:GetPlayers()) do
  38. if otherPlayer ~= player then -- Don't include yourself
  39. local playerButton = Instance.new("TextButton")
  40. playerButton.Size = UDim2.new(1, 0, 0, 50) -- Full width, 50 height
  41. playerButton.Text = otherPlayer.Name
  42. playerButton.TextColor3 = Color3.fromRGB(255, 255, 255) -- White text
  43. playerButton.BackgroundTransparency = 1 -- Fully transparent background
  44. playerButton.BorderSizePixel = 0 -- No border
  45. playerButton.Parent = userFrame
  46.  
  47. -- Teleport to the player when clicked
  48. playerButton.MouseButton1Click:Connect(function()
  49. if otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  50. player.Character:MoveTo(otherPlayer.Character.HumanoidRootPart.Position) -- Teleport to the player
  51. end
  52. end)
  53. end
  54. end
  55.  
  56. -- Adjust the canvas size of the scrollable frame based on the number of players
  57. userFrame.CanvasSize = UDim2.new(0, 0, 0, listLayout.AbsoluteContentSize.Y)
  58. end
  59.  
  60. -- Populate usernames initially
  61. populateUsernames()
  62.  
  63. -- Update usernames when a player joins or leaves
  64. Players.PlayerAdded:Connect(function()
  65. wait(0.1) -- Wait a moment for the new player to fully join
  66. populateUsernames()
  67. end)
  68.  
  69. Players.PlayerRemoving:Connect(function()
  70. wait(0.1) -- Wait a moment for the player to leave
  71. populateUsernames()
  72. end)
  73.  
  74. -- Create a ScreenGui for the control buttons (exit and open)
  75. local controlGui = Instance.new("ScreenGui")
  76. controlGui.Parent = playerGui
  77.  
  78. -- Create the "Open" button
  79. local openButton = Instance.new("TextButton")
  80. openButton.Size = UDim2.new(0, 100, 0, 50)
  81. openButton.Position = UDim2.new(0, 10, 0, 10) -- Top left corner
  82. openButton.Text = "Open"
  83. openButton.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Green background
  84. openButton.TextColor3 = Color3.fromRGB(255, 255, 255) -- White text
  85. openButton.Parent = controlGui
  86. openButton.Visible = false -- Initially hidden (since the GUI is already open)
  87.  
  88. -- Create a UICorner for rounded corners on the "Open" button
  89. local openButtonCorner = Instance.new("UICorner")
  90. openButtonCorner.CornerRadius = UDim.new(0, 12) -- Adjust for softer corners
  91. openButtonCorner.Parent = openButton
  92.  
  93. -- Create the "Exit" button
  94. local exitButton = Instance.new("TextButton")
  95. exitButton.Size = UDim2.new(0, 100, 0, 50)
  96. exitButton.Position = UDim2.new(0, 10, 0, 10) -- Top left corner (same position as the Open button)
  97. exitButton.Text = "Exit"
  98. exitButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Red background
  99. exitButton.TextColor3 = Color3.fromRGB(255, 255, 255) -- White text
  100. exitButton.Parent = controlGui
  101.  
  102. -- Create a UICorner for rounded corners on the "Exit" button
  103. local exitButtonCorner = Instance.new("UICorner")
  104. exitButtonCorner.CornerRadius = UDim.new(0, 12) -- Adjust for softer corners
  105. exitButtonCorner.Parent = exitButton
  106.  
  107. -- Close the GUI when the Exit button is clicked, and show the Open button
  108. exitButton.MouseButton1Click:Connect(function()
  109. userFrame.Visible = false -- Hide the player list
  110. exitButton.Visible = false -- Hide the Exit button
  111. openButton.Visible = true -- Show the Open button
  112. end)
  113.  
  114. -- Open the GUI when the Open button is clicked, and show the Exit button
  115. openButton.MouseButton1Click:Connect(function()
  116. userFrame.Visible = true -- Show the player list
  117. exitButton.Visible = true -- Show the Exit button
  118. openButton.Visible = false -- Hide the Open button
  119. end)
  120.  
  121. -- Adjust the canvas size whenever the layout changes (like when players join/leave)
  122. listLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
  123. userFrame.CanvasSize = UDim2.new(0, 0, 0, listLayout.AbsoluteContentSize.Y)
  124. end)
Advertisement
Add Comment
Please, Sign In to add comment