666thedemon666

Roblox TP gui script V2

Dec 14th, 2024 (edited)
2,573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.06 KB | None | 0 0
  1. -- Services
  2. local plr = game:GetService("Players").LocalPlayer
  3. local mouse = plr:GetMouse()
  4. local UIS = game:GetService("UserInputService")
  5. local teleporting = false
  6. local dragging = false
  7. local dragStart = nil
  8. local startPos = nil
  9. local teleportEnabled = false -- Keep track of teleportation status
  10.  
  11. -- Function to find a player by partial username or display name
  12. local function findPlayerByPartialName(partialName)
  13. local partialLower = string.lower(partialName) -- Case insensitive match
  14. for _, player in pairs(game:GetService("Players"):GetPlayers()) do
  15. -- Check if either the player's Username or DisplayName contains the partialName
  16. if string.find(string.lower(player.Name), partialLower) or string.find(string.lower(player.DisplayName), partialLower) then
  17. return player -- Return the first player that matches
  18. end
  19. end
  20. return nil -- Return nil if no matching player is found
  21. end
  22.  
  23. -- Function to check for a safe height and avoid collision
  24. local function getSafeHeight(position)
  25. local raycastResult = workspace:Raycast(position, Vector3.new(0, -50, 0)) -- Raycast downward to check for ground
  26. if raycastResult then
  27. return raycastResult.Position.Y + 5 -- Add a small offset above the ground to prevent clipping
  28. else
  29. return position.Y -- Return the original height if no ground is found
  30. end
  31. end
  32.  
  33. -- Function to check if the destination position is clear (not colliding with objects)
  34. local function isPositionClear(position)
  35. local raycastResult = workspace:Raycast(position, Vector3.new(0, 5, 0)) -- Cast ray upwards to check for collisions
  36. return raycastResult == nil -- If there's no hit, the position is clear
  37. end
  38.  
  39. -- Teleportation when pressing 'E'
  40. UIS.InputBegan:Connect(function(input, gameProcessed)
  41. if gameProcessed then return end
  42. if input.KeyCode == Enum.KeyCode.E and teleportEnabled and not teleporting then
  43. teleporting = true
  44. local mousePos = mouse.Hit.p
  45. -- Adjust the position to a safe height
  46. local adjustedPos = getSafeHeight(mousePos)
  47.  
  48. -- Check if the position is clear
  49. if isPositionClear(Vector3.new(mousePos.X, adjustedPos, mousePos.Z)) then
  50. -- Teleport to the point clicked
  51. if plr.Character then
  52. local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
  53. if hrp then
  54. hrp.CFrame = CFrame.new(Vector3.new(mousePos.X, adjustedPos, mousePos.Z))
  55. end
  56. end
  57. else
  58. print("Clicked position is blocked. Teleportation canceled.")
  59. end
  60.  
  61. teleporting = false -- Reset teleporting state
  62. end
  63. end)
  64.  
  65. -- GUI Creation (updated with a smaller frame and larger fonts)
  66. local gui = Instance.new("ScreenGui", plr:WaitForChild("PlayerGui"))
  67. gui.Name = "ModernUI_V2"
  68.  
  69. local frame = Instance.new("Frame", gui)
  70. frame.Size = UDim2.new(0, 350, 0, 250) -- Smaller size of the GUI (compared to before)
  71. frame.Position = UDim2.new(0.5, -175, 0.5, -125)
  72. frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
  73. frame.BorderSizePixel = 0
  74. frame.AnchorPoint = Vector2.new(0.5, 0.5)
  75.  
  76. local frameCorner = Instance.new("UICorner", frame)
  77. frameCorner.CornerRadius = UDim.new(0.05, 0) -- Subtle rounded corners
  78.  
  79. -- Title Bar (Updated to V2)
  80. local title = Instance.new("TextLabel", frame)
  81. title.Size = UDim2.new(1, 0, 0.15, 0)
  82. title.Position = UDim2.new(0, 0, 0, 0)
  83. title.BackgroundTransparency = 1
  84. title.Text = "Made by 666team6666 V2"
  85. title.TextColor3 = Color3.fromRGB(255, 255, 255)
  86. title.Font = Enum.Font.GothamBold
  87. title.TextSize = 18 -- Increased font size
  88. title.TextStrokeTransparency = 0.5
  89. title.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  90.  
  91. -- Textbox for Username Input
  92. local textbox = Instance.new("TextBox", frame)
  93. textbox.Size = UDim2.new(0.8, 0, 0.15, 0)
  94. textbox.Position = UDim2.new(0.1, 0, 0.2, 0)
  95. textbox.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  96. textbox.Text = ""
  97. textbox.PlaceholderText = "Enter Username (Partial OK)"
  98. textbox.Font = Enum.Font.Gotham
  99. textbox.TextColor3 = Color3.fromRGB(255, 255, 255)
  100. textbox.TextSize = 16 -- Increased font size for better readability
  101. textbox.TextStrokeTransparency = 0.8
  102. textbox.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  103.  
  104. local textboxCorner = Instance.new("UICorner", textbox)
  105. textboxCorner.CornerRadius = UDim.new(0.1, 0) -- Rounded corners for textbox
  106.  
  107. -- Select Button (Dark Green by Default)
  108. local selectButton = Instance.new("TextButton", frame)
  109. selectButton.Size = UDim2.new(0.8, 0, 0.15, 0)
  110. selectButton.Position = UDim2.new(0.1, 0, 0.4, 0)
  111. selectButton.BackgroundColor3 = Color3.fromRGB(0, 75, 0) -- Dark Green color (solid)
  112. selectButton.Text = "Select (Teleport)"
  113. selectButton.Font = Enum.Font.Gotham
  114. selectButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  115. selectButton.TextSize = 16 -- Increased font size
  116. selectButton.TextStrokeTransparency = 0.8
  117. selectButton.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  118.  
  119. local selectCorner = Instance.new("UICorner", selectButton)
  120. selectCorner.CornerRadius = UDim.new(0.1, 0) -- Rounded corners for button
  121.  
  122. -- Enable Button (True Dark Blue)
  123. local enable = Instance.new("TextButton", frame)
  124. enable.Size = UDim2.new(0.8, 0, 0.15, 0)
  125. enable.Position = UDim2.new(0.1, 0, 0.6, 0)
  126. enable.BackgroundColor3 = Color3.fromRGB(0, 0, 100) -- Dark Blue
  127. enable.Text = "Enable Teleportation"
  128. enable.Font = Enum.Font.Gotham
  129. enable.TextColor3 = Color3.fromRGB(255, 255, 255)
  130. enable.TextSize = 16 -- Increased font size
  131. enable.TextStrokeTransparency = 0.8
  132. enable.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  133.  
  134. local enableCorner = Instance.new("UICorner", enable)
  135. enableCorner.CornerRadius = UDim.new(0.1, 0) -- Rounded corners for the button
  136.  
  137. -- Disable Button (True Dark Red)
  138. local disable = Instance.new("TextButton", frame)
  139. disable.Size = UDim2.new(0.8, 0, 0.15, 0)
  140. disable.Position = UDim2.new(0.1, 0, 0.8, 0)
  141. disable.BackgroundColor3 = Color3.fromRGB(100, 0, 0) -- Dark Red
  142. disable.Text = "Disable Teleportation"
  143. disable.Font = Enum.Font.Gotham
  144. disable.TextColor3 = Color3.fromRGB(255, 255, 255)
  145. disable.TextSize = 16 -- Increased font size
  146. disable.TextStrokeTransparency = 0.8
  147. disable.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  148.  
  149. local disableCorner = Instance.new("UICorner", disable)
  150. disableCorner.CornerRadius = UDim.new(0.1, 0) -- Rounded corners for the button
  151.  
  152. -- Close Button (Positioned top right inside the frame, smaller and interactive)
  153. local close = Instance.new("TextButton", frame)
  154. close.Size = UDim2.new(0.1, 0, 0.1, 0) -- Smaller size for the close button
  155. close.Position = UDim2.new(1, -40, 0, 10) -- Top-right corner inside the frame
  156. close.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
  157. close.Text = "X"
  158. close.Font = Enum.Font.GothamBold
  159. close.TextColor3 = Color3.fromRGB(255, 255, 255)
  160. close.TextSize = 18 -- Increased font size for the close button
  161. close.TextStrokeTransparency = 0.8
  162. close.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
  163.  
  164. local closeCorner = Instance.new("UICorner", close)
  165. closeCorner.CornerRadius = UDim.new(0.2, 0)
  166.  
  167. -- Close button function (to destroy the GUI)
  168. close.MouseButton1Click:Connect(function()
  169. gui:Destroy() -- Close the GUI
  170. end)
  171.  
  172. -- Close button hover interaction
  173. close.MouseEnter:Connect(function()
  174. close.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Turn red when hovered
  175. end)
  176.  
  177. close.MouseLeave:Connect(function()
  178. close.BackgroundColor3 = Color3.fromRGB(45, 45, 45) -- Return to original color when not hovered
  179. end)
  180.  
  181. -- Teleport to Player based on Username or Display Name
  182. selectButton.MouseButton1Click:Connect(function()
  183. local username = textbox.Text
  184. local targetPlayer = findPlayerByPartialName(username) -- Check for partial username or display name
  185. if targetPlayer and targetPlayer.Character then
  186. local targetHRP = targetPlayer.Character:FindFirstChild("HumanoidRootPart")
  187. if targetHRP then
  188. local targetPos = targetHRP.Position
  189. -- Adjust to safe height if necessary
  190. local adjustedHeight = getSafeHeight(targetPos)
  191. targetPos = Vector3.new(targetPos.X, adjustedHeight, targetPos.Z)
  192. -- Ensure position is clear
  193. if isPositionClear(targetPos) then
  194. -- Teleport to the player
  195. if plr.Character then
  196. local hrp = plr.Character:FindFirstChild("HumanoidRootPart")
  197. if hrp then
  198. hrp.CFrame = CFrame.new(targetPos)
  199. end
  200. end
  201. else
  202. print("Target position blocked. Teleportation canceled.")
  203. end
  204. end
  205. else
  206. print("Player not found.")
  207. end
  208. end)
  209.  
  210. -- Enable teleportation functionality
  211. enable.MouseButton1Click:Connect(function()
  212. teleportEnabled = true -- Enable teleportation
  213. print("Teleportation enabled.")
  214. end)
  215.  
  216. -- Disable teleportation functionality
  217. disable.MouseButton1Click:Connect(function()
  218. teleportEnabled = false -- Disable teleportation
  219. print("Teleportation disabled.")
  220. end)
  221.  
  222. -- Dragging functionality
  223. frame.InputBegan:Connect(function(input)
  224. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  225. dragging = true
  226. dragStart = input.Position
  227. startPos = frame.Position
  228. end
  229. end)
  230.  
  231. frame.InputChanged:Connect(function(input)
  232. if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
  233. local delta = input.Position - dragStart
  234. frame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  235. end
  236. end)
  237.  
  238. frame.InputEnded:Connect(function(input)
  239. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  240. dragging = false
  241. end
  242. end)
  243.  
  244. -- Automatically disable teleportation when the player dies
  245. plr.CharacterAdded:Connect(function(character)
  246. teleportEnabled = false -- Disable teleportation when a new character spawns
  247. end)
  248.  
  249. plr.CharacterRemoving:Connect(function(character)
  250. teleportEnabled = false -- Disable teleportation when the player dies
  251. end)
  252.  
Advertisement
Add Comment
Please, Sign In to add comment