1 | -- loadstring(game:HttpGet("https://pastecode.dev/raw/qlug4oiw/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 | -- Check if the player is above you |
27 | local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart") |
28 | if hrp then |
29 | local hrpPos = hrp.Position |
30 | local yOffset = -0.1 -- below you |
31 | if targetPosition.Y >= hrpPos.Y + yOffset then |
32 | nearestDistance = distance |
33 | nearestTarget = otherPlayer |
34 | end |
35 | end |
36 | end |
37 | end |
38 | end |
39 | end |
40 | |
41 | return nearestTarget |
42 | end |
43 | |
44 | -- Function to move to the nearest target's left arm, avoiding the right arm |
45 | local function moveToNearestTarget() |
46 | if not toggled then return end |
47 | |
48 | local target = findNearestTarget() |
49 | if target then |
50 | local leftArm = target.Character:FindFirstChild("Left Arm") or target.Character:FindFirstChild("LeftUpperArm") |
51 | local rightArm = target.Character:FindFirstChild("Right Arm") or target.Character:FindFirstChild("RightUpperArm") |
52 | if leftArm and rightArm then |
53 | local character = player.Character |
54 | local humanoid = character and character:FindFirstChild("Humanoid") |
55 | local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart") |
56 | if humanoid and humanoidRootPart then |
57 | -- Move to the offset position near the left arm |
58 | local offsetDirection = (leftArm.Position - rightArm.Position).unit |
59 | local offsetPosition = leftArm.Position + offsetDirection * 3 -- 3 studs offset from the left arm |
60 | humanoid:MoveTo(offsetPosition) |
61 | |
62 | -- Make the character look at the left arm without changing pitch and rotate left |
63 | local lookAtPosition = Vector3.new(leftArm.Position.X, humanoidRootPart.Position.Y, leftArm.Position.Z) |
64 | humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) * CFrame.Angles(0, math.rad(13), 0) |
65 | end |
66 | end |
67 | end |
68 | end |
69 | |
70 | -- Toggle function |
71 | local function toggleMovement(input) |
72 | if input.KeyCode == Enum.KeyCode.Q then |
73 | toggled = not toggled |
74 | end |
75 | end |
76 | |
77 | -- Connect the toggle function to user input |
78 | userInputService.InputBegan:Connect(toggleMovement) |
79 | |
80 | -- Connect the movement function to the RenderStepped event |
81 | runService.RenderStepped:Connect(moveToNearestTarget) |