Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local plr = game.Players.LocalPlayer
- local plrMouse = plr:GetMouse()
- local repStorage = game:GetService('ReplicatedStorage')
- local updateArms = repStorage:WaitForChild('updateArms')
- local char = plr.Character or plr.CharacterAdded:Wait()
- local Torso = char:WaitForChild("Torso")
- local Head = char:WaitForChild("Head")
- local Neck = Torso:WaitForChild("Neck")
- local Humanoid = char:WaitForChild("Humanoid")
- local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
- local Camera = workspace.CurrentCamera
- local RunService = game:GetService("RunService")
- local Arms = {char:WaitForChild("Left Arm");char:WaitForChild("Right Arm")}
- local Sides = {'Left','Right'}
- local NeckOriginC0 = Neck.C0
- local ArmsOrigin = {}
- for i = 1,#Arms do
- ArmsOrigin[i] = Torso[Sides[i]..' Shoulder'].C0
- end
- Neck.MaxVelocity = 1/3
- local connection
- local timing = tick()
- local duration = 1/60
- local function followMouse()
- connection = RunService.RenderStepped:Connect(function()
- if (tick() - timing >= duration) then
- timing = tick()
- if char:FindFirstChild("Torso") and char:FindFirstChild("Head") then
- local TorsoLookVector = Torso.CFrame.lookVector
- local HeadPosition = Head.CFrame.p
- if Neck then
- if Camera.CameraSubject:IsDescendantOf(char) or Camera.CameraSubject:IsDescendantOf(plr) then
- local hitPos = plrMouse.Hit.p
- local dist = (Head.CFrame.p - hitPos).magnitude
- local dif = Head.CFrame.Y - hitPos.Y
- local tblToSend = {}
- tblToSend[1] = {Neck,Neck.C0:lerp(NeckOriginC0 * CFrame.Angles((math.atan(dif / dist) * 0.5), 0, 0), 1)}
- for i = 1,#Arms do
- 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)}
- end
- updateArms:FireServer(tblToSend)
- end
- end
- end
- end
- end)
- end
- updateArms.OnClientEvent:Connect(function(tbl)
- print('UPDATING ARMS')
- for i = 1,#tbl do
- tbl[i][1].C0 = tbl[i][2]
- end
- end)
- script.Parent.Equipped:Connect(followMouse)
- script.Parent.Unequipped:Connect(function()
- connection:Disconnect()
- local tblToSend = {}
- tblToSend[1] = {Neck,NeckOriginC0}
- for i = 1,#Arms do
- tblToSend[i+1] = {Torso[Sides[i]..' Shoulder'],ArmsOrigin[i]}
- end
- updateArms:FireServer(tblToSend)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement