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 Mouse = Players.LocalPlayer:GetMouse() local camera = workspace.CurrentCamera local function getClosestPlayer() local closestPlayer local closestDistance = math.huge for _, player in ipairs(Players:GetPlayers()) do if player ~= Players.LocalPlayer then local distance = (Players.LocalPlayer.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude if distance < closestDistance then closestDistance = distance closestPlayer = player end end end return closestPlayer end Mouse.Button2Down:Connect(function() local targetPlayer = getClosestPlayer() if targetPlayer then camera.CameraSubject = targetPlayer.Character.Humanoid end end) Mouse.Button2Up:Connect(function() camera.CameraSubject = Players.LocalPlayer.Character.Humanoid end)