RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a script that puts my camera on the nearest enemy player"
-- local script local Players = game:GetService("Players") local LocalPlayer = Players.LocalPlayer local Camera = game.Workspace.CurrentCamera while wait(1) do local closestPlayer local shortestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do if player ~= LocalPlayer and player.TeamColor ~= LocalPlayer.TeamColor and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then local distance = (LocalPlayer.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude if distance < shortestDistance then shortestDistance = distance closestPlayer = player end end end if closestPlayer then Camera.CameraSubject = closestPlayer.Character.Humanoid end end