script rush test 5 or whatever lol

public
vxpreen Jul 21, 2024 Never 37
Clone
Lua paste1.lua 93 lines (80 loc) | 4.5 KB
1
-- loadstring(game:HttpGet("https://pastecode.dev/raw/r2ts7ue3/paste1.lua"))()
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 rightArm 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
local head = target.Character:FindFirstChild("Head")
53
if leftArm and rightArm and head then
54
local character = player.Character
55
local humanoid = character and character:FindFirstChild("Humanoid")
56
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
57
if humanoid and humanoidRootPart then
58
-- Check if the target is looking at the player
59
local directionToPlayer = (player.Character.HumanoidRootPart.Position - head.Position).unit
60
local targetLookDirection = head.CFrame.LookVector.unit
61
local dotProduct = directionToPlayer:Dot(targetLookDirection)
62
63
-- If the target is looking at the player or the right arm is in the path
64
if dotProduct > 0.5 or (rightArm.Position - humanoidRootPart.Position).magnitude < 5 then
65
-- Move to the offset position to the side of the left arm
66
local offsetDirection = (leftArm.Position - rightArm.Position).unit
67
local offsetPosition = leftArm.Position + offsetDirection * 3 -- 3 studs offset from the left arm
68
humanoid:MoveTo(offsetPosition)
69
70
-- Make the character look at the left arm without changing pitch and rotate left
71
local lookAtPosition = Vector3.new(leftArm.Position.X, humanoidRootPart.Position.Y, leftArm.Position.Z)
72
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) * CFrame.Angles(0, math.rad(25), 0)
73
else
74
-- Move to the left arm directly
75
humanoid:MoveTo(leftArm.Position)
76
end
77
end
78
end
79
end
80
end
81
82
-- Toggle function
83
local function toggleMovement(input)
84
if input.KeyCode == Enum.KeyCode.Q then
85
toggled = not toggled
86
end
87
end
88
89
-- Connect the toggle function to user input
90
userInputService.InputBegan:Connect(toggleMovement)
91
92
-- Connect the movement function to the RenderStepped event
93
runService.RenderStepped:Connect(moveToNearestTarget)