RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a roblox script whenever i hold down right click my mouse locks on to the most close player"
-- local script local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local LocalPlayer = Players.LocalPlayer local Mouse = LocalPlayer:GetMouse() local function getClosestPlayer() local closestPlayer = nil local shortestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do if player ~= LocalPlayer then local distance = (LocalPlayer.Character.Head.Position - player.Character.Head.Position).magnitude if distance < shortestDistance then closestPlayer = player shortestDistance = distance end end end return closestPlayer end local function onMouseDown() local closestPlayer = getClosestPlayer() if closestPlayer then Mouse.TargetFilter = closestPlayer.Character Mouse.Icon = "rbxassetid://LockOnIconID" -- Replace with the ID of your lock-on icon end end local function onMouseUp() Mouse.TargetFilter = nil Mouse.Icon = "" end UserInputService.InputBegan:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.MouseButton2 and not gameProcessed then onMouseDown() end end) UserInputService.InputEnded:Connect(function(input, gameProcessed) if input.UserInputType == Enum.UserInputType.MouseButton2 and not gameProcessed then onMouseUp() end end)