I was following a tutorial on making a katana with wielding for the first time and it was going well until I added the animations
I have already double checked the animations and they are in the correct spot and start when need to but the katana will no longer pull out of its sword. Does anyone know how to fix it? Here is the code that “Broke”
local rp = game:GetService("ReplicatedStorage")
local Sword = rp:WaitForChild("Sword")
local debounce = true
local cframes = {
["Right Arm"] = CFrame.new(0,-1,-0),
["RightHand"] = CFrame.new(0,0,0)
}
Sword.OnServerEvent:Connect(function(Player,isEquipped)
local Character = Player.Character
local Humanoid = Character.Humanoid
if isEquipped then
--Equiping the Sword
local Katana = Character:FindFirstChild("Katana")
if Katana then
local equipAnim
local swordAnim
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
equipAnim = Humanoid.Animator:LoadAnimation(script.R6.Equip)
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
equipAnim = Humanoid.Animator:LoadAnimation(script.R6.Equip)
swordAnim = Katana.Controller.Animator:LoadAnimation(script.R6.KatanaR6)
end
equipAnim:Play()
equipAnim:GetMarkerReachedSignal("Sword"):Connect(function()
local Katana = Character:FindFirstChild("Katana")
if Katana then
local SideWeld = Katana.PrimaryPart:FindFirstChild("SideWeld")
if SideWeld then
SideWeld:Destroy()
swordAnim:Play()
local RightHandle = script.RightHandle:Clone()
if Humanoid.RigType == Enum.HumanoidRigType.R15 then
RightHandle.CFrame = Character:WaitForChild("RightHand").CFrame * cframes.RightHand
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
RightHandle.CFrame = Character:WaitForChild("Right Arm").CFrame * cframes["Right Arm"]
end
RightHandle.Parent = Character
local weld = Instance.new("ManualWeld")
weld.Part0 = RightHandle
if Humanoid.RigType == Enum.HumanoidRigType.R15 then
weld.Part1 = Character:WaitForChild("RightHand")
elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
weld.Part1 = Character:WaitForChild("Right Arm")
end
RightHandle.Parent = Character
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
Katana:SetPrimaryPartCFrame(RightHandle.CFrame)
local Motor6D = Instance.new("Motor6D")
Motor6D.Part0 = Katana.PrimaryPart
Motor6D.Part1 = RightHandle
Motor6D.C0 = Motor6D.Part0.CFrame:ToObjectSpace(Motor6D.Part1.CFrame)
Motor6D.Parent = Motor6D.Part0
end
end
end)
equipAnim.Stopped:Connect(function()
local Idle
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
Idle = Humanoid.Animator:LoadAnimation(script.R6.Idle)
end
Idle:Play()
end)
end
elseif not isEquipped then
--Unequipping the Sword
local Katana = Character:FindFirstChild("Katana")
if Katana then
local RightHandle = Character:FindFirstChild("RightHandle")
if RightHandle then
RightHandle:Destroy()
local Case = Character:FindFirstChild("Case")
if Case then
Katana:SetPrimaryPartCFrame(Case.Case.CFrame*CFrame.new(0,-.125,2.65))
local weld2 = Instance.new("ManualWeld")
weld2.Name = "SideWeld"
weld2.Part0 = Katana.PrimaryPart
weld2.Part1 = Case.PrimaryPart
weld2.C0 = weld2.Part0.CFrame:ToObjectSpace(weld2.Part1.CFrame)
weld2.Parent = weld2.Part0
Sword:FireClient(Player)
end
end
end
end
end)
and here is the code that works fine but is involved -
SwordCombat LocalScript in Starterpack
local rp = game:GetService("ReplicatedStorage")
local Sword = rp:WaitForChild("Sword")
local UIS = game:GetService("UserInputService")
local isEquipped = false
local debounce = false
local cd = 1
UIS.InputBegan:Connect(function(input,IsTyping)
if not IsTyping then
if input.KeyCode == Enum.KeyCode.E then
if not isEquipped and not debounce then
isEquipped = true
Sword:FireServer(isEquipped)
elseif isEquipped and not debounce then
debounce = true
isEquipped = false
Sword:FireServer(isEquipped)
end
end
end
end)
Sword.OnClientEvent:Connect(function()
wait(cd)
debounce = false
end)
SwordSpawn script in ServerScriptService
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character.Humanoid
local Case = script.Case:Clone()
Case:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame)
Case.Parent = Character
local weld = Instance.new("ManualWeld")
weld.Part0 = Case.PrimaryPart
weld.Part1 = Character.PrimaryPart
if Humanoid.RigType == Enum.HumanoidRigType.R6 then
weld.Part1 = Character.PrimaryPart
elseif Humanoid.RigType == Enum.HumanoidRigType.R15 then
return
end
weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
weld.Parent = weld.Part0
local Sword = script.Katana:Clone()
Sword:SetPrimaryPartCFrame(Case.Case.CFrame*CFrame.new(0,-.125,2.65))
Sword.Parent = Character
local weld2 = Instance.new("ManualWeld")
weld2.Name = "SideWeld"
weld2.Part0 = Sword.PrimaryPart
weld2.Part1 = Case.PrimaryPart
weld2.C0 = weld2.Part0.CFrame:ToObjectSpace(weld2.Part1.CFrame)
weld2.Parent = weld2.Part0
end)
end)
Here is a example of the issue
(it is in the animation but the sword isn’t in the hand)