Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lock Script for Da Hood
- -- Get the closest player
- local function getClosestPlayer()
- local closestPlayer = nil
- local closestDistance = math.huge
- for _, player in pairs(game:GetService("Players"):GetPlayers()) do
- if player ~= game:GetService("Players").LocalPlayer then
- local character = player.Character
- if character then
- local distance = (character.HumanoidRootPart.Position - game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.Position).Magnitude
- if distance < closestDistance then
- closestDistance = distance
- closestPlayer = player
- end
- end
- end
- end
- return closestPlayer
- end
- -- Lock onto the closest player
- local function lock()
- local closestPlayer = getClosestPlayer()
- if closestPlayer then
- local character = closestPlayer.Character
- if character then
- local humanoidRootPart = character.HumanoidRootPart
- game:GetService("Workspace").CurrentCamera.CFrame = CFrame.new(game:GetService("Workspace").CurrentCamera.CFrame.Position, humanoidRootPart.Position)
- game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -3)
- end
- end
- end
- -- Run the lock function every frame
- game:GetService("RunService").RenderStepped:Connect(lock)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement