papapyst

Invisible - Made by @pystYT

Oct 5th, 2024
3,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. -- Function to create a button in the player's UI
  2. local function createTeleportButton()
  3. -- Create a ScreenGui
  4. local screenGui = Instance.new("ScreenGui")
  5. screenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  6.  
  7. -- Create the button
  8. local button = Instance.new("TextButton")
  9. button.Size = UDim2.new(0, 40, 0, 40) -- Smaller button size
  10. button.Position = UDim2.new(1, -60, 0, 10) -- Position at top right corner
  11. button.BackgroundColor3 = Color3.fromRGB(0, 0, 128) -- Dark blue color
  12. button.Text = "Invisible" -- Button text
  13. button.TextColor3 = Color3.fromRGB(255, 255, 255) -- White text
  14. button.FontSize = Enum.FontSize.Size14 -- Smaller text size
  15. button.TextScaled = true -- Automatically scale text to fit button size
  16. button.Parent = screenGui
  17.  
  18. -- Create squircle shape
  19. local uiCorner = Instance.new("UICorner") -- Create a UICorner instance
  20. uiCorner.CornerRadius = UDim.new(0, 20) -- Adjust the radius for squircle effect
  21. uiCorner.Parent = button
  22.  
  23. local lastPosition = nil
  24. local camera = game.Workspace.CurrentCamera
  25. local randomTeleportDistance = 500 -- Minimum distance for random teleport
  26. local isFrozen = false -- Track whether the character is frozen
  27. local originalCameraPosition = nil -- Store original camera CFrame
  28. local dragging = false
  29. local lastTouchPosition = nil -- Store the last touch position for dragging
  30.  
  31. local UserInputService = game:GetService("UserInputService") -- Input handling service
  32.  
  33. -- Function to show notification
  34. local function showNotification()
  35. local player = game.Players.LocalPlayer
  36. player:WaitForChild("PlayerGui"):SetCore("SendNotification", {
  37. Title = "Teleport Button Created",
  38. Text = "Click the 'Invisible' button to teleport your character while keeping the camera fixed!",
  39. Duration = 5 -- Duration in seconds
  40. })
  41. end
  42.  
  43. -- Function to teleport the character to a random position
  44. local function teleportToRandomPosition()
  45. local player = game.Players.LocalPlayer
  46. local character = player.Character
  47.  
  48. if character and character:FindFirstChild("HumanoidRootPart") then
  49. local humanoidRootPart = character.HumanoidRootPart
  50. local newPosition
  51.  
  52. -- Capture and lock the camera's current position
  53. originalCameraPosition = camera.CFrame
  54.  
  55. -- Generate a new position until it is far enough from the current position
  56. repeat
  57. newPosition = Vector3.new(
  58. math.random(-2000, 2000), -- Increased random range
  59. 50, -- Adjust Y position to prevent falling
  60. math.random(-2000, 2000) -- Increased random range
  61. )
  62. until (newPosition - humanoidRootPart.Position).magnitude > randomTeleportDistance
  63.  
  64. lastPosition = humanoidRootPart.Position
  65. humanoidRootPart.CFrame = CFrame.new(newPosition)
  66.  
  67. -- Freeze the character and prevent falling
  68. local humanoid = character:FindFirstChild("Humanoid")
  69. if humanoid then
  70. isFrozen = true
  71. humanoid.PlatformStand = true -- Freeze the character in place
  72. humanoidRootPart.Anchored = true -- Prevent falling
  73. end
  74.  
  75. -- Make the camera draggable after teleport
  76. camera.CameraType = Enum.CameraType.Scriptable -- Set camera type for custom control
  77. end
  78. end
  79.  
  80. -- Function to teleport the character back to the last position
  81. local function teleportBack()
  82. local player = game.Players.LocalPlayer
  83. local character = player.Character
  84.  
  85. if character and character:FindFirstChild("HumanoidRootPart") and lastPosition then
  86. character.HumanoidRootPart.CFrame = CFrame.new(lastPosition)
  87.  
  88. -- Unfreeze the character and allow falling again
  89. local humanoid = character:FindFirstChild("Humanoid")
  90. if humanoid then
  91. isFrozen = false
  92. humanoid.PlatformStand = false -- Unfreeze the character
  93. character.HumanoidRootPart.Anchored = false -- Allow falling again
  94. end
  95.  
  96. -- Return the camera to its default behavior
  97. camera.CameraType = Enum.CameraType.Custom -- Free camera control again
  98. lastPosition = nil -- Clear the last position after teleporting back
  99. end
  100. end
  101.  
  102. local toggleTeleport = false
  103.  
  104. -- Connect the button click event
  105. button.MouseButton1Click:Connect(function()
  106. if not toggleTeleport then
  107. teleportToRandomPosition() -- Teleport to a random position
  108. else
  109. teleportBack() -- Teleport back to the last position
  110. end
  111. toggleTeleport = not toggleTeleport -- Toggle between teleporting and returning
  112. end)
  113.  
  114. -- Handle touch input for dragging on mobile
  115. UserInputService.TouchStarted:Connect(function(input)
  116. if toggleTeleport and input.UserInputType == Enum.UserInputType.Touch then
  117. dragging = true
  118. lastTouchPosition = input.Position -- Store initial touch position
  119. end
  120. end)
  121.  
  122. UserInputService.TouchMoved:Connect(function(input)
  123. if dragging and toggleTeleport and input.UserInputType == Enum.UserInputType.Touch then
  124. local delta = input.Position - lastTouchPosition -- Calculate change in touch position
  125. local moveDirection = Vector3.new(-delta.X * 0.1, delta.Y * 0.1, 0) -- Adjust movement scale
  126. camera.CFrame = camera.CFrame * CFrame.new(moveDirection) -- Move the camera
  127. lastTouchPosition = input.Position -- Update touch position
  128. end
  129. end)
  130.  
  131. UserInputService.TouchEnded:Connect(function(input)
  132. if input.UserInputType == Enum.UserInputType.Touch then
  133. dragging = false -- Stop dragging when touch ends
  134. end
  135. end)
  136.  
  137. -- Maintain camera at the original location if frozen
  138. game:GetService("RunService").RenderStepped:Connect(function()
  139. if toggleTeleport then
  140. -- Camera is initially locked at the original position, but then draggable
  141. end
  142. end)
  143.  
  144. -- Show notification upon script execution
  145. showNotification()
  146. end
  147.  
  148. -- Execute the button creation function
  149. createTeleportButton()
Advertisement
Add Comment
Please, Sign In to add comment