Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

invalid argument #2 (Vector3 expected, got nil) I'm getting this how to I fix it?

Asked by 2 years ago
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

0
When you're looking at it use the view source button as it makes it easier to read because it's not cut off then. LiamQ926 7 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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.

0
Thank you! It's now working perfectly LiamQ926 7 — 2y
0
You’re welcome! T3_MasterGamer 2189 — 2y
0
Please accept my answer so many people can see it. T3_MasterGamer 2189 — 2y
0
Where do I accept it LiamQ926 7 — 2y
Ad

Answer this question