Advertisement
Guest User

da hood camlock.lua

a guest
Feb 8th, 2025
1,564
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. --// Settings
  2. local lockKey = Enum.KeyCode.Q -- Key to toggle lock
  3. local breakKey = Enum.KeyCode.P -- Key to break script
  4. local fovRadius = 100 -- Field of View for camlock
  5. local lockTarget = nil
  6. local isLocked = false
  7. local running = true
  8.  
  9. local UserInputService = game:GetService("UserInputService")
  10. local Players = game:GetService("Players")
  11. local RunService = game:GetService("RunService")
  12.  
  13. local localPlayer = Players.LocalPlayer
  14. local camera = workspace.CurrentCamera
  15.  
  16. local fovCircle = Drawing.new("Circle")
  17. fovCircle.Thickness = 1
  18. fovCircle.NumSides = 64
  19. fovCircle.Radius = fovRadius
  20. fovCircle.Filled = false
  21. fovCircle.Color = Color3.fromRGB(255, 0, 0)
  22. fovCircle.Visible = true
  23.  
  24. local function getClosestPlayer()
  25. local closestPlayer = nil
  26. local shortestDistance = fovRadius
  27.  
  28. for _, player in ipairs(Players:GetPlayers()) do
  29. if player ~= localPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  30. local targetPos = camera:WorldToViewportPoint(player.Character.HumanoidRootPart.Position)
  31. local mousePos = UserInputService:GetMouseLocation()
  32. local distance = (Vector2.new(targetPos.X, targetPos.Y) - mousePos).Magnitude
  33.  
  34. if distance < shortestDistance then
  35. closestPlayer = player
  36. shortestDistance = distance
  37. end
  38. end
  39. end
  40.  
  41. return closestPlayer
  42. end
  43.  
  44. local function toggleLock()
  45. if isLocked then
  46. isLocked = false
  47. lockTarget = nil
  48. fovCircle.Color = Color3.fromRGB(255, 0, 0)
  49. else
  50. lockTarget = getClosestPlayer()
  51. if lockTarget then
  52. isLocked = true
  53. fovCircle.Color = Color3.fromRGB(0, 255, 0)
  54. end
  55. end
  56. end
  57.  
  58. RunService.RenderStepped:Connect(function()
  59. local mousePos = UserInputService:GetMouseLocation()
  60. fovCircle.Position = Vector2.new(mousePos.X, mousePos.Y)
  61.  
  62. if isLocked and lockTarget and lockTarget.Character and lockTarget.Character:FindFirstChild("HumanoidRootPart") then
  63. local target = lockTarget.Character.HumanoidRootPart
  64. camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
  65. end
  66. end)
  67.  
  68. UserInputService.InputBegan:Connect(function(input, isProcessed)
  69. if isProcessed then return end
  70.  
  71. if input.KeyCode == lockKey then
  72. toggleLock()
  73. elseif input.KeyCode == breakKey then
  74. running = false
  75. isLocked = false
  76. lockTarget = nil
  77. fovCircle:Remove()
  78. script:Destroy()
  79. end
  80. end)
  81.  
  82. while running do
  83. task.wait()
  84. end
  85.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement