RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make my mouse cursor point to the nearest person when i hold right click"
-- local script local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local localPlayer = Players.LocalPlayer local camera = workspace.CurrentCamera local function getNearestPlayer() local nearestPlayer = nil local nearestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do if player ~= localPlayer then local distance = (player.Character.HumanoidRootPart.Position - localPlayer.Character.HumanoidRootPart.Position).magnitude if distance < nearestDistance then nearestPlayer = player nearestDistance = distance end end end return nearestPlayer end local function onInputBegan(input, gameProcessed) if input.UserInputType == Enum.UserInputType.MouseButton2 then local nearestPlayer = getNearestPlayer() if nearestPlayer then local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position local direction = (targetPosition - camera.CFrame.Position).unit local ray = Ray.new(camera.CFrame.Position, direction * 1000) local hit, position = workspace:FindPartOnRay(ray, localPlayer.Character) if hit then localPlayer:GetMouse().Hit = position end end end end UserInputService.InputBegan:Connect(onInputBegan)