1 | -- loadstring(game:HttpGet("https://pastecode.dev/raw/hlhz1vr4/paste1.txt"))() |
2 | |
3 | local player = game.Players.LocalPlayer |
4 | local userInputService = game:GetService("UserInputService") |
5 | local runService = game:GetService("RunService") |
6 | |
7 | local toggled = false |
8 | |
9 | -- Function to find the nearest target |
10 | local function findNearestTarget() |
11 | local nearestDistance = math.huge |
12 | local nearestTarget = nil |
13 | local playerPosition = player.Character and player.Character:FindFirstChild("HumanoidRootPart").Position |
14 | |
15 | if not playerPosition then return end |
16 | |
17 | for _, otherPlayer in ipairs(game.Players:GetPlayers()) do |
18 | if otherPlayer.Character and otherPlayer ~= player then |
19 | local humanoid = otherPlayer.Character:FindFirstChild("Humanoid") |
20 | local leftArm = otherPlayer.Character:FindFirstChild("Left Arm") or otherPlayer.Character:FindFirstChild("LeftUpperArm") |
21 | local rightArm = otherPlayer.Character:FindFirstChild("Right Arm") or otherPlayer.Character:FindFirstChild("RightUpperArm") |
22 | if humanoid and leftArm and humanoid.Health > 0 then |
23 | local targetPosition = leftArm.Position |
24 | local distance = (targetPosition - playerPosition).magnitude |
25 | if distance < 16 and distance < nearestDistance then |
26 | nearestDistance = distance |
27 | nearestTarget = otherPlayer |
28 | end |
29 | end |
30 | end |
31 | end |
32 | |
33 | return nearestTarget |
34 | end |
35 | |
36 | -- Function to move to the nearest target's left arm, avoiding the right arm |
37 | local function moveToNearestTarget() |
38 | if not toggled then return end |
39 | |
40 | local target = findNearestTarget() |
41 | if target then |
42 | local leftArm = target.Character:FindFirstChild("Left Arm") or target.Character:FindFirstChild("LeftUpperArm") |
43 | local rightArm = target.Character:FindFirstChild("Right Arm") or target.Character:FindFirstChild("RightUpperArm") |
44 | if leftArm and rightArm then |
45 | local character = player.Character |
46 | local humanoid = character and character:FindFirstChild("Humanoid") |
47 | local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart") |
48 | if humanoid and humanoidRootPart then |
49 | -- Calculate positions |
50 | local targetPosition = leftArm.Position |
51 | local playerPosition = humanoidRootPart.Position |
52 | local rightArmPosition = rightArm.Position |
53 | |
54 | -- Calculate direction vectors |
55 | local targetDirection = (targetPosition - playerPosition).unit |
56 | local rightArmDirection = (rightArmPosition - playerPosition).unit |
57 | |
58 | -- Determine safe position away from right arm |
59 | local safeDistance = 6 |
60 | local evasionDirection = targetDirection + rightArmDirection * 0.5 |
61 | local finalPosition = targetPosition + evasionDirection.unit * safeDistance |
62 | |
63 | -- Move to final position without changing speed |
64 | humanoid.MoveTo(humanoidRootPart, finalPosition) |
65 | |
66 | -- Adjust character orientation to face the left arm |
67 | local lookAtPosition = Vector3.new(targetPosition.X, humanoidRootPart.Position.Y, targetPosition.Z) |
68 | humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) |
69 | |
70 | -- Fine-tune rotation to avoid pitching up or down |
71 | local currentRotation = humanoidRootPart.Rotation |
72 | humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) * CFrame.Angles(0, currentRotation.Y, 0) |
73 | end |
74 | end |
75 | end |
76 | end |
77 | |
78 | -- Toggle function |
79 | local function toggleMovement(input) |
80 | if input.KeyCode == Enum.KeyCode.Q then |
81 | toggled = not toggled |
82 | end |
83 | end |
84 | |
85 | -- Connect the toggle function to user input |
86 | userInputService.InputBegan:Connect(toggleMovement) |
87 | |
88 | -- Connect the movement function to the RenderStepped event |
89 | runService.RenderStepped:Connect(moveToNearestTarget) |