Advertisement
rrixh

Untitled

Sep 18th, 2024
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. -- Lock Script for Da Hood
  2.  
  3. -- Get the closest player
  4. local function getClosestPlayer()
  5.   local closestPlayer = nil
  6.   local closestDistance = math.huge
  7.   for _, player in pairs(game:GetService("Players"):GetPlayers()) do
  8.     if player ~= game:GetService("Players").LocalPlayer then
  9.       local character = player.Character
  10.       if character then
  11.         local distance = (character.HumanoidRootPart.Position - game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
  12.         if distance < closestDistance then
  13.           closestDistance = distance
  14.           closestPlayer = player
  15.         end
  16.       end
  17.     end
  18.   end
  19.   return closestPlayer
  20. end
  21.  
  22. -- Lock onto the closest player
  23. local function lock()
  24.   local closestPlayer = getClosestPlayer()
  25.   if closestPlayer then
  26.     local character = closestPlayer.Character
  27.     if character then
  28.       local humanoidRootPart = character.HumanoidRootPart
  29.       game:GetService("Workspace").CurrentCamera.CFrame = CFrame.new(game:GetService("Workspace").CurrentCamera.CFrame.Position, humanoidRootPart.Position)
  30.       game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -3)
  31.     end
  32.   end
  33. end
  34.  
  35. -- Run the lock function every frame
  36. game:GetService("RunService").RenderStepped:Connect(lock)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement