Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

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.

1 answer

✓ Accepted answer

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.

4 comments

0

Thank you! It's now working perfectly

0

You’re welcome!

0

Please accept my answer so many people can see it.

0

Where do I accept it

This discussion is preserved as it was. New answers, comments, and votes are closed.