RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make my mouse cursor point to the nearest person when i hold right click"
-- local script local player = game.Players.LocalPlayer local mouse = player:GetMouse() local camera = game.Workspace.CurrentCamera local function findNearestPlayer() local nearestPlayer = nil local nearestDistance = math.huge for _, otherPlayer in pairs(game.Players:GetPlayers()) do if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("Humanoid") and otherPlayer.Character.Humanoid.Health > 0 then local distance = (otherPlayer.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude if distance < nearestDistance then nearestPlayer = otherPlayer nearestDistance = distance end end end return nearestPlayer end mouse.Button2Down:Connect(function() local nearestPlayer = findNearestPlayer() if nearestPlayer then local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position local direction = (targetPosition - camera.CFrame.Position).unit local lookAt = CFrame.new(camera.CFrame.Position, targetPosition) camera.CFrame = lookAt * CFrame.new(0, 0, -5) end end)