Roblox script rushing

public
vxpreen Jun 09, 2024 Never 136
Clone
Lua paste1.txt 73 lines (61 loc) | 3.28 KB
1
-- loadstring(game:HttpGet("https://pastecode.dev/raw/2gpuwfue/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
local function findNearestTarget()
10
local nearestDistance = math.huge
11
local nearestTarget = nil
12
local playerPosition = player.Character and player.Character:FindFirstChild("HumanoidRootPart").Position
13
14
if not playerPosition then return end
15
16
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
17
if otherPlayer.Character and otherPlayer ~= player then
18
local humanoid = otherPlayer.Character:FindFirstChild("Humanoid")
19
local leftArm = otherPlayer.Character:FindFirstChild("Left Arm") or otherPlayer.Character:FindFirstChild("LeftUpperArm")
20
local rightArm = otherPlayer.Character:FindFirstChild("Right Arm") or otherPlayer.Character:FindFirstChild("RightUpperArm")
21
if humanoid and leftArm and humanoid.Health > 0 then
22
local targetPosition = leftArm.Position
23
local distance = (targetPosition - playerPosition).magnitude
24
if distance < 16 and distance < nearestDistance then
25
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
26
if hrp then
27
local hrpPos = hrp.Position
28
local yOffset = -0.1 -- below you
29
if targetPosition.Y >= hrpPos.Y + yOffset then
30
nearestDistance = distance
31
nearestTarget = otherPlayer
32
end
33
end
34
end
35
end
36
end
37
end
38
39
return nearestTarget
40
end
41
42
local function moveToNearestTarget()
43
if not toggled then return end
44
45
local target = findNearestTarget()
46
if target then
47
local leftArm = target.Character:FindFirstChild("Left Arm") or target.Character:FindFirstChild("LeftUpperArm")
48
local rightArm = target.Character:FindFirstChild("Right Arm") or target.Character:FindFirstChild("RightUpperArm")
49
if leftArm and rightArm then
50
local character = player.Character
51
local humanoid = character and character:FindFirstChild("Humanoid")
52
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
53
if humanoid and humanoidRootPart then
54
local offsetDirection = (leftArm.Position - rightArm.Position).unit
55
local offsetPosition = leftArm.Position + offsetDirection * 3 -- studs offset from the left arm
56
humanoid:MoveTo(offsetPosition)
57
58
local lookAtPosition = Vector3.new(leftArm.Position.X, humanoidRootPart.Position.Y, leftArm.Position.Z)
59
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) * CFrame.Angles(0, math.rad(31), 0)
60
end
61
end
62
end
63
end
64
65
local function toggleMovement(input)
66
if input.KeyCode == Enum.KeyCode.Q then
67
toggled = not toggled
68
end
69
end
70
71
userInputService.InputBegan:Connect(toggleMovement)
72
73
runService.RenderStepped:Connect(moveToNearestTarget)