Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local aimlockRange = 100 -- Adjust the range to your preference
- local predictionFactor = 0.13 -- Adjust the prediction factor to your preference
- -- Function to find the nearest player
- local function findNearestPlayer()
- local mouse = game.Players.LocalPlayer:GetMouse()
- local target = nil
- local minDist = aimlockRange
- for _, player in ipairs(game.Players:GetPlayers()) do
- if player ~= game.Players.LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
- local char = player.Character
- local screenPos = game.Workspace.CurrentCamera:WorldToScreenPoint(char.HumanoidRootPart.Position)
- local dist = (Vector2.new(screenPos.X, screenPos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
- if dist < minDist then
- minDist = dist
- target = char.HumanoidRootPart
- end
- end
- end
- return target
- end
- -- Enable aimlock immediately when the script runs
- local aimlockEnabled = true
- local lockedPlayer = findNearestPlayer() -- Find the nearest player when aimlock is enabled
- -- Function to handle aimlock rendering with prediction
- game:GetService("RunService").RenderStepped:Connect(function()
- if aimlockEnabled and lockedPlayer then
- local targetPos = lockedPlayer.Position
- local targetVelocity = lockedPlayer.Velocity
- local predictedPos = targetPos + targetVelocity * predictionFactor
- local camera = game.Workspace.CurrentCamera
- camera.CFrame = CFrame.new(camera.CFrame.Position, predictedPos)
- end
- end)
- -- Handle aimlock behavior with 'F' key
- game:GetService("UserInputService").InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.F then
- if aimlockEnabled and lockedPlayer then
- lockedPlayer = nil
- elseif aimlockEnabled then
- lockedPlayer = findNearestPlayer()
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement