Advertisement
DanielSiqueira

ArmsFollow

Mar 1st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2. local plrMouse = plr:GetMouse()
  3.  
  4. local repStorage = game:GetService('ReplicatedStorage')
  5. local updateArms = repStorage:WaitForChild('updateArms')
  6.  
  7. local char = plr.Character or plr.CharacterAdded:Wait()
  8.  
  9. local Torso = char:WaitForChild("Torso")
  10. local Head = char:WaitForChild("Head")
  11. local Neck = Torso:WaitForChild("Neck")
  12.  
  13. local Humanoid = char:WaitForChild("Humanoid")
  14. local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
  15.  
  16. local Camera = workspace.CurrentCamera
  17. local RunService = game:GetService("RunService")
  18.  
  19. local Arms = {char:WaitForChild("Left Arm");char:WaitForChild("Right Arm")}
  20. local Sides = {'Left','Right'}
  21.  
  22. local NeckOriginC0 = Neck.C0
  23.  
  24. local ArmsOrigin = {}
  25.  
  26. for i = 1,#Arms do
  27. ArmsOrigin[i] = Torso[Sides[i]..' Shoulder'].C0
  28. end
  29.  
  30. Neck.MaxVelocity = 1/3
  31.  
  32. local connection
  33.  
  34. local timing = tick()
  35. local duration = 1/60
  36.  
  37. local function followMouse()
  38. connection = RunService.RenderStepped:Connect(function()
  39. if (tick() - timing >= duration) then
  40. timing = tick()
  41. if char:FindFirstChild("Torso") and char:FindFirstChild("Head") then
  42. local TorsoLookVector = Torso.CFrame.lookVector
  43. local HeadPosition = Head.CFrame.p
  44.  
  45. if Neck then
  46. if Camera.CameraSubject:IsDescendantOf(char) or Camera.CameraSubject:IsDescendantOf(plr) then
  47.  
  48. local hitPos = plrMouse.Hit.p
  49. local dist = (Head.CFrame.p - hitPos).magnitude
  50. local dif = Head.CFrame.Y - hitPos.Y
  51. local tblToSend = {}
  52. tblToSend[1] = {Neck,Neck.C0:lerp(NeckOriginC0 * CFrame.Angles((math.atan(dif / dist) * 0.5), 0, 0), 1)}
  53. for i = 1,#Arms do
  54. tblToSend[i+1] = {Torso[Sides[i].." Shoulder"],Torso[Sides[i]..' Shoulder'].C0:lerp(ArmsOrigin[i] * CFrame.Angles(0,0,i == 1 and (math.atan(dif / dist) * 1) or -(math.atan(dif / dist) * 1)), 1)}
  55. end
  56. updateArms:FireServer(tblToSend)
  57. end
  58. end
  59. end
  60. end
  61. end)
  62. end
  63.  
  64. updateArms.OnClientEvent:Connect(function(tbl)
  65. print('UPDATING ARMS')
  66. for i = 1,#tbl do
  67. tbl[i][1].C0 = tbl[i][2]
  68. end
  69. end)
  70.  
  71. script.Parent.Equipped:Connect(followMouse)
  72. script.Parent.Unequipped:Connect(function()
  73. connection:Disconnect()
  74. local tblToSend = {}
  75. tblToSend[1] = {Neck,NeckOriginC0}
  76. for i = 1,#Arms do
  77. tblToSend[i+1] = {Torso[Sides[i]..' Shoulder'],ArmsOrigin[i]}
  78. end
  79. updateArms:FireServer(tblToSend)
  80. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement