Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local Camera = workspace.CurrentCamera
- -- Check if a player has a ForceField
- local function hasForceField(player)
- if player.Character then
- return player.Character:FindFirstChildOfClass("ForceField") ~= nil
- end
- return false
- end
- -- Find the closest player to the local player
- local function findClosestPlayer()
- local localPlayer = Players.LocalPlayer
- local closestPlayer = nil
- local shortestDistance = math.huge
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= localPlayer and player.Character and player.Character:FindFirstChild("Head") then
- -- Skip players with ForceField
- if not hasForceField(player) then
- local head = player.Character.Head
- local distance = (localPlayer.Character.HumanoidRootPart.Position - head.Position).magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- closestPlayer = player
- end
- end
- end
- end
- return closestPlayer
- end
- -- Function to make the camera aim at the closest player's head
- local function aimCameraAtClosestPlayer()
- RunService.RenderStepped:Connect(function()
- if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then -- Check if right mouse button is held down
- local closestPlayer = findClosestPlayer()
- if closestPlayer and closestPlayer.Character and closestPlayer.Character:FindFirstChild("Head") then
- local head = closestPlayer.Character.Head
- -- Adjust the camera to look at the target's head
- Camera.CFrame = CFrame.new(Camera.CFrame.Position, head.Position)
- end
- end
- end)
- end
- -- Initialize the aim feature
- aimCameraAtClosestPlayer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement