Sword Rotation gets messed up?
The sword Rotation gets messed up when I try to sheathe it while walking. If I sheathe it standing still it works fine like this
https://gyazo.com/74c616449fd7f56b07722bd07e6e3119
But If I walk then the sword rotation gets messed up like this
https://gyazo.com/a608a3b138a900c9a45a952527bac02a
Code:
01 | equipAnim = script.Parent:WaitForChild( "EquipAnim5" ) |
02 | idleAnim = script.Parent:WaitForChild( "IdleAnim3" ) |
03 | sheatheAnim = script.Parent:WaitForChild( "SheatheAnim" ) |
04 | player = game.Players.LocalPlayer |
05 | rootPart = player.Character:FindFirstChild( "HumanoidRootPart" ) |
08 | rightArm = player.Character:FindFirstChild( "Right Arm" ) |
09 | katana = player.Character.Katana |
12 | function drawSword(inputObject, gameProcessedEvent) |
13 | if inputObject.KeyCode = = Enum.KeyCode.E then |
17 | local playEquipAnim = player.Character.Humanoid:LoadAnimation(equipAnim) |
20 | local oldWeld = katana:FindFirstChild( "Weld" ) |
26 | katana.CFrame = player.Character:WaitForChild( "Right Arm" ).CFrame * CFrame.new( 0 , - 1 , - 1.7 ) |
27 | katana.CFrame = katana.CFrame * CFrame.Angles( 59.7 , 0 , - 190 ) |
30 | local newWeld = Instance.new( "Weld" ) |
32 | newWeld.Part 0 = rightArm |
33 | newWeld.C 0 = rightArm.CFrame:inverse() |
34 | newWeld.Part 1 = katana |
35 | newWeld.C 1 = katana.CFrame:inverse() |
36 | newWeld.Parent = katana |
41 | playIdleAnim = player.Character.Humanoid:LoadAnimation(idleAnim) |
47 | game:GetService( "UserInputService" ).InputBegan:connect(drawSword) |
49 | function sheatheSword(inputObject, gameProcessedEvent) |
50 | if inputObject.KeyCode = = Enum.KeyCode.E then |
51 | if equipped = = false then |
52 | local playSheatheAnim = player.Character.Humanoid:LoadAnimation(sheatheAnim) |
53 | playSheatheAnim:Play() |
57 | local equippedWeld = script.Parent:FindFirstChild( "Weld" ) |
59 | equippedWeld:Destroy() |
62 | katana.CFrame = player.Character:FindFirstChild( "Left Leg" ).CFrame * CFrame.new(-. 6 , . 2 , 1.7 ) |
63 | katana.CFrame = katana.CFrame * CFrame.Angles(. 3 , 0 , 1.5 ) |
68 | local sheatheWeld = Instance.new( "Weld" ) |
69 | sheatheWeld.Name = "Weld" |
70 | sheatheWeld.Part 0 = rootPart |
71 | sheatheWeld.C 0 = rootPart.CFrame:inverse() |
72 | sheatheWeld.Part 1 = katana |
73 | sheatheWeld.C 1 = katana.CFrame:inverse() |
74 | sheatheWeld.Parent = katana |
83 | game:GetService( "UserInputService" ).InputBegan:connect(sheatheSword) |
How do I make it so the rotation doesn't get messed up when sheathing while walking?