rushshhshrunng

public
vxpreen Jun 12, 2024 Never 66
Clone
Plaintext paste1.txt 105 lines (92 loc) | 4.59 KB
1
-- loadstring(game:HttpGet("https://pastecode.dev/raw/tuf25pz3/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
local disableDueToMovement = false
9
10
-- Function to find the nearest target
11
local function findNearestTarget()
12
local nearestDistance = math.huge
13
local nearestTarget = nil
14
local playerPosition = player.Character and player.Character:FindFirstChild("HumanoidRootPart").Position
15
16
if not playerPosition then return end
17
18
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
19
if otherPlayer.Character and otherPlayer ~= player then
20
local humanoid = otherPlayer.Character:FindFirstChild("Humanoid")
21
local leftArm = otherPlayer.Character:FindFirstChild("Left Arm") or otherPlayer.Character:FindFirstChild("LeftUpperArm")
22
local rightArm = otherPlayer.Character:FindFirstChild("Right Arm") or otherPlayer.Character:FindFirstChild("RightUpperArm")
23
if humanoid and leftArm and humanoid.Health > 0 then
24
local targetPosition = leftArm.Position
25
local distance = (targetPosition - playerPosition).magnitude
26
if distance < 16 and distance < nearestDistance then
27
-- Check if the player is above you
28
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
29
if hrp then
30
local hrpPos = hrp.Position
31
local yOffset = -0.1 -- below you
32
if targetPosition.Y >= hrpPos.Y + yOffset then
33
nearestDistance = distance
34
nearestTarget = otherPlayer
35
end
36
end
37
end
38
end
39
end
40
end
41
42
return nearestTarget
43
end
44
45
-- Function to move to the nearest target's left arm, avoiding the right arm
46
local function moveToNearestTarget()
47
if not toggled or disableDueToMovement then return end
48
49
local target = findNearestTarget()
50
if target then
51
local leftArm = target.Character:FindFirstChild("Left Arm") or target.Character:FindFirstChild("LeftUpperArm")
52
local rightArm = target.Character:FindFirstChild("Right Arm") or target.Character:FindFirstChild("RightUpperArm")
53
if leftArm and rightArm 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
-- Move to the offset position near the left arm
59
local offsetDirection = (leftArm.Position - rightArm.Position).unit
60
local offsetPosition = leftArm.Position + offsetDirection * 3 -- 3 studs offset from the left arm
61
humanoid:MoveTo(offsetPosition)
62
63
-- Make the character look at the left arm without changing pitch and rotate left
64
local lookAtPosition = Vector3.new(leftArm.Position.X, humanoidRootPart.Position.Y, leftArm.Position.Z)
65
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, lookAtPosition) * CFrame.Angles(0, math.rad(10), 0)
66
end
67
end
68
end
69
end
70
71
-- Function to check if the player is moving backwards
72
local function checkMovement()
73
if player.Character then
74
local humanoid = player.Character:FindFirstChild("Humanoid")
75
if humanoid then
76
local moveDirection = humanoid.MoveDirection
77
local hrp = player.Character:FindFirstChild("HumanoidRootPart")
78
if hrp then
79
local forwardDirection = hrp.CFrame.lookVector
80
-- If the dot product is less than zero, the player is moving backwards
81
if moveDirection:Dot(forwardDirection) < 0 then
82
disableDueToMovement = true
83
else
84
disableDueToMovement = false
85
end
86
end
87
end
88
end
89
end
90
91
-- Toggle function
92
local function toggleMovement(input)
93
if input.KeyCode == Enum.KeyCode.Q then
94
toggled = not toggled
95
end
96
end
97
98
-- Connect the toggle function to user input
99
userInputService.InputBegan:Connect(toggleMovement)
100
101
-- Connect the movement function to the RenderStepped event
102
runService.RenderStepped:Connect(function()
103
checkMovement()
104
moveToNearestTarget()
105
end)