Advertisement
ColdSpecs

Final Freecam Script Trident (BEST ONE SO FAR)

Aug 11th, 2024
30
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. -- Update: Made Freecam tp sync with current camera state.
  2. -- Working On Trident 2024!!!
  3.  
  4. -- Services
  5. local UIS = game:GetService("UserInputService")
  6. local RS = game:GetService("RunService")
  7. local Camera = workspace.CurrentCamera
  8.  
  9. -- Variables
  10. local keybind_freecam_toggle = Enum.KeyCode.P -- Assign a key to toggle freecam
  11. local keybind_teleport = Enum.KeyCode.Y
  12. local speed = 0.9
  13. local droneCFrame
  14. local HighlightFolder = Instance.new("Folder", workspace)
  15. HighlightFolder.Name = "ESPHighlights"
  16. local freecamEnabled = false -- State variable for toggle
  17.  
  18. -- Function to create highlight
  19. local function createHighlight(part)
  20. local highlight = Instance.new("Highlight")
  21. highlight.Adornee = part
  22. highlight.FillTransparency = 0.7
  23. highlight.OutlineTransparency = 0.3
  24. highlight.FillColor = Color3.fromRGB(75, 0, 130)
  25. highlight.OutlineColor = Color3.fromRGB(75, 0, 130)
  26. highlight.Parent = HighlightFolder
  27. return highlight
  28. end
  29.  
  30. -- Function to get nearest adornee to mouse position
  31. local function getNearestAdornee()
  32. local cursorPosition = UIS:GetMouseLocation()
  33. local nearestAdornee = nil
  34. local smallestDistance = math.huge
  35.  
  36. for _, highlight in ipairs(HighlightFolder:GetChildren()) do
  37. if highlight:IsA("Highlight") and highlight.Adornee then
  38. local adorneePosition, onScreen = Camera:WorldToScreenPoint(highlight.Adornee.Position)
  39. if onScreen then
  40. local distance = (Vector2.new(adorneePosition.X, adorneePosition.Y) - cursorPosition).Magnitude
  41. if distance < smallestDistance then
  42. smallestDistance = distance
  43. nearestAdornee = highlight.Adornee
  44. end
  45. end
  46. end
  47. end
  48.  
  49. return nearestAdornee
  50. end
  51.  
  52. -- Function to teleport camera to nearest adornee
  53. local function teleportToNearestAdornee()
  54. local nearestAdornee = getNearestAdornee()
  55. if nearestAdornee then
  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 freecamEnabled then
  82. -- Sync freecam start position with current camera position
  83. droneCFrame = Camera.CFrame
  84. else
  85. -- Optional: Reset the camera to the player's current position when freecam is disabled
  86. local player = game.Players.LocalPlayer
  87. if player and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  88. Camera.CFrame = player.Character.HumanoidRootPart.CFrame
  89. end
  90. end
  91. end
  92.  
  93. -- Connect the toggle function to a key input
  94. UIS.InputBegan:Connect(function(input, processed)
  95. if not processed then
  96. if input.KeyCode == keybind_freecam_toggle then
  97. toggleFreecam()
  98. end
  99. if input.KeyCode == keybind_teleport then
  100. -- Teleport whether freecam is active or not
  101. teleportToNearestAdornee()
  102. end
  103. end
  104. end)
  105.  
  106. RS.RenderStepped:Connect(updateFreecam)
  107.  
  108. -- Initialization: ESP setup
  109. local function toggleESP()
  110. local neonParts = workspace:GetDescendants()
  111. for _, part in ipairs(neonParts) do
  112. if part:IsA("UnionOperation") and part.Name == "State" and part.Material == Enum.Material.Neon then
  113. createHighlight(part)
  114. end
  115. end
  116.  
  117. workspace.DescendantAdded:Connect(function(part)
  118. if part:IsA("UnionOperation") and part.Name == "State" and part.Material == Enum.Material.Neon then
  119. createHighlight(part)
  120. end
  121. end)
  122. end
  123.  
  124. toggleESP() -- Enable ESP by default
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement