local rp = game:GetService("ReplicatedStorage") local Sword = rp:WaitForChild("Sword") local cframes = { ["Right Arm"] = CFrame.new(0,-1,0), ["Right Hand"] = CFrame.new(0,0,0) } Sword.OnServerEvent:Connect(function(Player,isEquipped) local Character = Player.Character local Humanoid = Character.Humanoid if isEquipped then --Equipping the sword local Katana = Character:FindFirstChild("Katana") if Katana then local SideWeld = Katana.PrimaryPart:FindFirstChild("SideWeld") if SideWeld then SideWeld:Destroy() if Humanoid.RigType == Enum.HumanoidRigType.R15 then Katana:SetPrimaryPartCFrame(Character:WaitForChild("RightHand").CFrame * cframes.RightHand) elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then Katana:SetPrimaryPartCFrame(Character:WaitForChild("Right Arm").CFrame * cframes["Right Arm"]) end local HandWeld = Instance.new("ManualWeld") HandWeld.Part0 = Katana.PrimaryPart if Humanoid.RigType == Enum.HumanoidRigType.R15 then HandWeld.Part1 = Character:WaitForChild("Righthand") -- this is the errored line elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then HandWeld.Part1 = Character:WaitForChild("Right Arm") end HandWeld.C0 = > HandWeld.Part0.CFrame:ToObjectSpace(HandWeld.Part1.CFrame) HandWeld.Parent = HandWeld.Part0 end end elseif not isEquipped then --Unequipping the sword end end)
Note: This problem only happens in R15 and I want the game to be compatible with both R15 and R6
In line 22, you’re trying to find RightHand in a table called cframes. But “RightHand” does not exist in that table because the Right Hand in the table has a space between. You either change that line to
Katana:SetPrimaryPartCFrame(Character:WaitForChild("RightHand").CFrame * cframes[“Right Hand”])
or change the table to
local cframes = { ["Right Arm"] = CFrame.new(0,-1,0), ["RightHand"] = CFrame.new(0,0,0) }
and for the “errored line” simply change it to
HandWeld.Part1 = Character:WaitForChild("RightHand")
because you typed the H as a lowercase, which can cause errors.
Also I highly recommend to use Tool.Equiped
and Tool.Unequipped
inside of the tool instead.