I am trying to make a script in which the player’s arm follows the item when it’s grabbed and so i merged this function with another script and made this:
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Neck", true)
local Shoulder = Character.RightUpperArm:FindFirstChild("RightShoulder", true)
local defpos = Shoulder.C0
local YOffset = Neck.C0.Y
local CFNew, CFAng = CFrame.new, CFrame.Angles
local asin = math.asin
game:GetService("RunService").RenderStepped:Connect(function()
local CameraDirection = Root.CFrame:toObjectSpace(mouse.Hit).lookVector
local armOffset = Character.UpperTorso.CFrame:Inverse() * Character.RightUpperArm.CFrame
if Neck then
if Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
Neck.C0 = CFNew(0, YOffset, 0) * CFAng(0, -asin(CameraDirection.x), 0) * CFAng(asin(CameraDirection.y), 0, 0)
if _G.ItemToFace ~= nil then
local armcframe = CFrame.new(Character.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
Shoulder.C0 = armOffset * Character.UpperTorso.CFrame:ToObjectSpace(armcframe)
else
Shoulder.C0 = defpos
end
elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
if _G.ItemToFace ~= nil then
local armcframe = CFrame.new(Character.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
Shoulder.C0 = armOffset * Character.UpperTorso.CFrame:ToObjectSpace(armcframe)
else
Shoulder.C0 = CFNew(0,0,0) * CFAng(0,0,0)
end
end
end
end)
game.ReplicatedStorage.Look.OnClientEvent:Connect(function(otherPlayer, neckCFrame, ShoulderCFrame)
local Neck = otherPlayer.Character:FindFirstChild("Neck", true)
local Shoulder = otherPlayer.Character:FindFirstChild("RightShoulder", true)
if Neck then
tweenService:Create(Neck, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = neckCFrame}):Play()
elseif Shoulder then
tweenService:Create(Shoulder, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = ShoulderCFrame}):Play()
end
end)
while wait() do
game.ReplicatedStorage.Look:FireServer(Neck.C0, Shoulder.C0)
end
https://gyazo.com/cf1625da1e4e0d569c5a844a4a37cce1
https://gyazo.com/34bf1ba7d75b8a26630211c068ea2780
(Screen on the left)
The arm goes into the person’s back and the Elbow isn’t straight it moves according to the roblox animation