Advertisement
ColdSpecs

Working Tp totum

Aug 11th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. -- Script to handle integrated teleportation and free camera control in Roblox with toggle
  2.  
  3. -- Services
  4. local UIS = game:GetService("UserInputService")
  5. local RS = game:GetService("RunService")
  6. local Camera = workspace.CurrentCamera
  7.  
  8. -- Variables
  9. local keybind_freecam_toggle = Enum.KeyCode.P -- Assign a key to toggle freecam
  10. local keybind_teleport = Enum.KeyCode.Y
  11. local speed = 0.9
  12. local droneCFrame = Camera.CFrame
  13. local HighlightFolder = Instance.new("Folder", workspace)
  14. HighlightFolder.Name = "ESPHighlights"
  15. local freecamEnabled = false -- State variable for toggle
  16.  
  17. -- Function to create highlight
  18. local function createHighlight(part)
  19. local highlight = Instance.new("Highlight")
  20. highlight.Adornee = part
  21. highlight.FillTransparency = 0.7
  22. highlight.OutlineTransparency = 0.3
  23. highlight.FillColor = Color3.fromRGB(75, 0, 130)
  24. highlight.OutlineColor = Color3.fromRGB(75, 0, 130)
  25. highlight.Parent = HighlightFolder
  26. return highlight
  27. end
  28.  
  29. -- Function to get nearest adornee to mouse position
  30. local function getNearestAdornee()
  31. local cursorPosition = UIS:GetMouseLocation()
  32. local nearestAdornee = nil
  33. local smallestDistance = math.huge
  34.  
  35. for _, highlight in ipairs(HighlightFolder:GetChildren()) do
  36. if highlight:IsA("Highlight") and highlight.Adornee then
  37. local adorneePosition, onScreen = Camera:WorldToScreenPoint(highlight.Adornee.Position)
  38. if onScreen then
  39. local distance = (Vector2.new(adorneePosition.X, adorneePosition.Y) - cursorPosition).Magnitude
  40. if distance < smallestDistance then
  41. smallestDistance = distance
  42. nearestAdornee = highlight.Adornee
  43. end
  44. end
  45. end
  46. end
  47.  
  48. return nearestAdornee
  49. end
  50.  
  51. -- Function to teleport camera to nearest adornee
  52. local function teleportToNearestAdornee()
  53. local nearestAdornee = getNearestAdornee()
  54. if nearestAdornee then
  55.  
  56. Camera.CFrame = nearestAdornee.CFrame
  57. droneCFrame = nearestAdornee.CFrame
  58. end
  59. end
  60.  
  61. -- Function to update the camera's free movement based on input
  62. local function updateFreecam()
  63. if freecamEnabled then
  64. local delta = UIS:GetMouseDelta()
  65. droneCFrame = droneCFrame * CFrame.Angles(-math.rad(delta.Y), -math.rad(delta.X), 0)
  66.  
  67. local mv = Vector3.new(
  68. (UIS:IsKeyDown(Enum.KeyCode.D) and speed or 0) - (UIS:IsKeyDown(Enum.KeyCode.A) and speed or 0),
  69. (UIS:IsKeyDown(Enum.KeyCode.Space) and speed or 0) - (UIS:IsKeyDown(Enum.KeyCode.LeftShift) and speed or 0),
  70. (UIS:IsKeyDown(Enum.KeyCode.S) and speed or 0) - (UIS:IsKeyDown(Enum.KeyCode.W) and speed or 0)
  71. )
  72.  
  73. droneCFrame = droneCFrame * CFrame.new(mv)
  74. Camera.CFrame = droneCFrame
  75. end
  76. end
  77.  
  78. -- Toggle function for freecam
  79. local function toggleFreecam()
  80. freecamEnabled = not freecamEnabled
  81. if not freecamEnabled then
  82. -- Optional: Reset the camera to the player's current position when freecam is disabled
  83. local player = game.Players.LocalPlayer
  84. if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  85. Camera.CFrame = player.Character.HumanoidRootPart.CFrame
  86. end
  87. end
  88. end
  89.  
  90. -- Connect the toggle function to a key input
  91. UIS.InputBegan:Connect(function(input, processed)
  92. if not processed then
  93. if input.KeyCode == keybind_freecam_toggle then
  94. toggleFreecam()
  95. end
  96. if input.KeyCode == keybind_teleport then
  97. -- Teleport whether freecam is active or not
  98. teleportToNearestAdornee()
  99. end
  100. end
  101. end)
  102.  
  103. RS.RenderStepped:Connect(updateFreecam)
  104.  
  105. -- Initialization: ESP setup
  106. local function toggleESP()
  107. local neonParts = workspace:GetDescendants()
  108. for _, part in ipairs(neonParts) do
  109. if part:IsA("UnionOperation") and part.Name == "State" and part.Material == Enum.Material.Neon then
  110. createHighlight(part)
  111. end
  112. end
  113.  
  114. workspace.DescendantAdded:Connect(function(part)
  115. if part:IsA("UnionOperation") and part.Name == "State" and part.Material == Enum.Material.Neon then
  116. createHighlight(part)
  117. end
  118. end)
  119. end
  120.  
  121. toggleESP() -- Enable ESP by default
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement