Rotation X

public
vxpreen Jun 22, 2024 Never 83
Clone
Plaintext paste1.txt 87 lines (73 loc) | 3.99 KB
1
-- loadstring(game:HttpGet("https://pastecode.dev/raw/2u0hx4n4/paste1.txt"))()
2
3
local player = game.Players.LocalPlayer
4
local userInputService = game:GetService("UserInputService")
5
local runService = game:GetService("RunService")
6
7
-- Adjustable parameters
8
local RotoSpeed = 0.7 -- Adjust this value for rotation speed
9
10
local toggled = false
11
12
-- Function to find the nearest target
13
local function findNearestTarget()
14
local nearestDistance = math.huge
15
local nearestTarget = nil
16
local playerPosition = player.Character and player.Character:FindFirstChild("HumanoidRootPart").Position
17
18
if not playerPosition then return end
19
20
for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
21
if otherPlayer.Character and otherPlayer ~= player then
22
local humanoid = otherPlayer.Character:FindFirstChild("Humanoid")
23
local leftArm = otherPlayer.Character:FindFirstChild("Left Arm") or otherPlayer.Character:FindFirstChild("LeftUpperArm")
24
local rightArm = otherPlayer.Character:FindFirstChild("Right Arm") or otherPlayer.Character:FindFirstChild("RightUpperArm")
25
if humanoid and leftArm and humanoid.Health > 0 then
26
local targetPosition = leftArm.Position
27
local distance = (targetPosition - playerPosition).magnitude
28
if distance < 16 and distance < nearestDistance then
29
-- Check if the player is above you
30
local hrp = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
31
if hrp then
32
local hrpPos = hrp.Position
33
local yOffset = -0.1 -- below you
34
if targetPosition.Y >= hrpPos.Y + yOffset then
35
nearestDistance = distance
36
nearestTarget = otherPlayer
37
end
38
end
39
end
40
end
41
end
42
end
43
44
return nearestTarget
45
end
46
47
-- Function to move to the nearest target's left arm, avoiding the right arm
48
local function moveToNearestTarget()
49
if not toggled then return end
50
51
local target = findNearestTarget()
52
if target then
53
local leftArm = target.Character:FindFirstChild("Left Arm") or target.Character:FindFirstChild("LeftUpperArm")
54
local rightArm = target.Character:FindFirstChild("Right Arm") or target.Character:FindFirstChild("RightUpperArm")
55
if leftArm and rightArm then
56
local character = player.Character
57
local humanoid = character and character:FindFirstChild("Humanoid")
58
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
59
if humanoid and humanoidRootPart then
60
-- Move to the offset position near the left arm
61
local offsetDirection = (leftArm.Position - rightArm.Position).unit
62
local offsetPosition = leftArm.Position + offsetDirection * 3 -- 3 studs offset from the left arm
63
humanoid:MoveTo(offsetPosition)
64
65
-- Calculate the direction to look at the left arm
66
local lookAtPosition = Vector3.new(leftArm.Position.X, humanoidRootPart.Position.Y, leftArm.Position.Z)
67
68
-- Smoothly interpolate rotation towards the left arm position
69
local newCFrame = humanoidRootPart.CFrame:Lerp(CFrame.new(humanoidRootPart.Position, lookAtPosition), RotoSpeed)
70
humanoidRootPart.CFrame = newCFrame * CFrame.Angles(0, math.rad(23), 0) -- Adjust pitch if needed
71
end
72
end
73
end
74
end
75
76
-- Toggle function
77
local function toggleMovement(input)
78
if input.KeyCode == Enum.KeyCode.Q then
79
toggled = not toggled
80
end
81
end
82
83
-- Connect the toggle function to user input
84
userInputService.InputBegan:Connect(toggleMovement)
85
86
-- Connect the movement function to the RenderStepped event
87
runService.RenderStepped:Connect(moveToNearestTarget)