Invalid argument #2 (Vector3 expected, got table)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

How would I fix this?

  1. What is the issue? Include screenshots / videos if possible!

Once I reload the gun completly detaches its self from the camera then an error pops up saying “invalid argument #2 (Vector3 expected, got table)”.
Video of what happens.
robloxapp-20220421-1515211.wmv (1.2 MB)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried looking at the developer hub and It did help a little. However, I started getting this error.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is the main script where I get the error.

Run.RenderStepped:connect(function()
	if WeaponInHand and LArm and RArm then
		gui.TextLabel.Text = "Ammo: "..ammo.."/30"
		if ammo <= maxAmmo/6 then
			gui.Low.Visible = true
		else
			gui.Low.Visible = false
		end
		mouse.TargetFilter = cam
		WeaponInHand:SetPrimaryPartCFrame(
			cam.CFrame
				* maincf
				* gunbobcf
				*reloadcf
				*sprintcf
				*recoilcf
				--*boltcf
				*aimcf
		)

		LArm:SetPrimaryPartCFrame(
			WeaponInHand.PrimaryPart.CFrame
				*Larcf

		)

		RArm:SetPrimaryPartCFrame(
			WeaponInHand.PrimaryPart.CFrame
				*rarmcf

		)

		if running then
			gunbobcf = gunbobcf:Lerp(CFrame.new(
				0.1 * math.sin(tick()* 2), --how intenses the x axis is
				0.1 * math.sin(tick() * 4	), -- how intense the y axis is
				0
				), 0.1)

			if sprinting then
				sprintcf = sprintcf:Lerp(WeaponData.SprintCFrame, 0.1)
			else
				sprintcf = sprintcf:Lerp(CFrame.new(), 0.1)
			end
		else
			gunbobcf = gunbobcf:Lerp(CFrame.new(), 0.1)
			sprintcf = sprintcf:Lerp(CFrame.new(), 0.)

		end

		if aiming then
			local tween = Tween:Create(cam, aimTween, {FieldOfView = 70/1.5}) -- current fov / zoom
			tween:Play()
			aimcf = aimcf:Lerp(WeaponData.AimCFrame, 0.1) -- the lower the number the slower the speed is
		else
			local tween = Tween:Create(cam, aimTween, {FieldOfView = 70}) -- current fov / zoom
			tween:Play()
			aimcf = aimcf:Lerp(CFrame.new(), 0.1)
		end
		recoilcf = recoilcf:Lerp(CFrame.new(),0.1)
	end
end)

function reload()
	user.InputBegan:Connect(function(key)

		if key.KeyCode == Enum.KeyCode.R then
			reloading = true
			reloadcf = WeaponData.GunAnimations.tacticalreload
			if reloading then
				sprinting = false
				events.Sprint:FireServer(14)
				local Mag = WeaponInHand:WaitForChild("Mag")
				reloadcf = reloadcf:Lerp(Vector3.new(), 0.1)
				Mag:WaitForChild("Reloadsn"):Play()
				wait(2)
				ammo = 30
				reloading = false
				wait(0.0001)
				shooting = false
			end
		end
	end)
end

Here is the Module script

local module = {}
local v3=Vector3.new
local cf=CFrame.new
local angles=CFrame.Angles
local deg=math.pi/180
local new=Instance.new
local function anglesyx(x,y)
	local cx=math.cos(x)
	return v3(-cx*math.sin(y),math.sin(x),-cx*math.cos(y))
end
print(1)

module.mainpart = "Handle"
module.mag = "Mag"
module.bolt = "Bolt"
module.barrel = "Muzzle"
module.sight = "SightMark"

module.MainCFrame = CFrame.new(0.5,-0.5,-0.75)
module.LArmCFrame = CFrame.new(-0.42,0.2,-2.5)
module.RArmCFrame = CFrame.new(0.2,-0.05,1)

module.AimCFrame = CFrame.new(-0.45,0,0.15)
module.zoom = 1.5
print(module.Parent)
module.ShootCFrame = CFrame.new(0,0,0.2) -- recoil
--module.BoltCFrame = -- bolt bacc
module.ShootType = 2 --[1 = semi] [2 = auto]
module.FireID = "rbxassetid://153230498"
module.FireRate = 600 -- bullets per minute
module.Damage = 40 --body shot damage
module.HeadDamage = 100 --headshot damage duh

module.SprintCFrame = CFrame.new(-0.3,-0.2,0) * CFrame.Angles(math.rad(40),math.rad(65), 0)

module.ReloadId = "rbxassetid://3742928054"

module.GunAnimations = {
	tacticalreload={
		--[[stdtimescale=0.5;
		timescale=0.5;--]]
		{
			{part="Trigger";c1=cf(-0.1,0.2,-0.13)*angles(9*deg,-5*deg,15*deg),t=1.1,eq="accelerate"};
			{part="larm";c1=cf(-0.27,-0.54,0.35)*angles(90*deg,-1*deg,15*deg),t=1,eq="decelerate"};
			delay=1
		},{
			{part="larm";c1=cf(-0.54,-1.4,0.11)*angles(67*deg,-11*deg,16*deg),t=0.4,eq="decelerate"};
			{part="Mag";c1=cf(-0.22,-1.76,-0.85)*angles(-169*deg,6*deg,-162*deg),t=0.4,eq="decelerate"};
			{part="Flame";sound=true,soundid="http://roblox.com/asset/?id=147323220",p=1,v=1,d=0.3};
			delay=0.1
		},{
			{part="Trigger";c1=cf(-0.18,0.25,-0.05)*angles(25*deg,4*deg,15*deg),t=0.8,eq={0,1.5,0.4,-0.4}};
			delay=0.3
		},{
			{part="Mag",clone="dropmag",transparency=1};
			{part="dropmag",drop=true,transparency=0},
			delay=0.1
		},{
			{part="Trigger";c1=cf(0.02,0.15,0.01)*angles(6*deg,-8*deg,-10*deg),t=1.5,eq="smooth"};
			{part="larm";c1=cf(-0.5,-1.2,0.8)*angles(58*deg,-23*deg,5*deg),t=0.8,eq="accelerate"};
			{part="Mag";c1=cf(-0.4,-1.23,-0.3)*angles(-139*deg,0*deg,-180*deg),t=0.8,eq="accelerate"};
			delay=0.8
		},{
			{part="larm";c1=cf(-0.25,-1.44,-0.35)*angles(110*deg,-11*deg,8*deg),t=0.8,eq="accelerate"};
			{part="Mag";c1=cf(-0.0,-0.6,-1)*angles(-140*deg,0*deg,-180*deg),transparency=0,t=0.8,eq="accelerate"};
			delay=0.7
		},{
			{part="Trigger";c1=cf(0.1,0.2,0.03)*angles(25*deg,-9*deg,-13*deg),t=0.6,eq={0,1.2,0.4,-0.2}};
			{part="Flame";sound=true,soundid="http://roblox.com/asset/?id=147323220",p=1.4,v=1,tp=0.8,d=0.5};
			delay=0.4
		},{
			{part="larm";c1=cf(-0.25,-0.85,0.35)*angles(90*deg,-15*deg,8*deg),t=0.2,eq="accelerate"};
			{part="Mag";c1="base",t=0.2,eq="accelerate"};

			delay=0.15
		},{
			{part="Trigger";c1=cf(0.16,0.33,0.15)*angles(28*deg,-10*deg,-12*deg),t=0.8,eq={0,2,0.3,-0.4}};
			delay=0.5
		},
	};
}


return module

(sorry bad english)

3 Likes

Could you show me which exact code is popping up this error?

1 Like

I’m on mobile right now, but I want to nit pick a little. (Not to do with the solution).
Your reload function is a little weird.
Firstly you shouldn’t run your reload code on client, because it’s easily exploitable. You should run a remote event. Also you denounce is a little weird, what’s the point of setting your ReloadBool to true, then checking if it is true a couple of lines later?

1 Like

Is where I’m getting the error.

When you multiply a CFrame like that, the variable needs to be a Vector3. However, the error is saying the variable is a table. The code you’re displaying for us doesn’t show where reloadcf is initialized. It does show inside the reload function that you are changing it to something named tacticalreload, which might be causing the error.

Which variable? The variable reloadcf is a CFrame. If I change it into Vector3 I get another error “invalid argument #1 (CFrame expected, got Vector3)”.

It’s not a CFrame like you said because the error says otherwise. If you want to confirm it, print out the type of reloadcf prior to the statement

print(typeof(reloadcf))

So how would I play CFrame values if they are in a table? I’m also getting an error:

Players.VoidPan_Dev.PlayerGui.LocalScript:139: attempt to call a nil value

				reloadcf = reloadcf:Lerp(Vector3.new(), 0.1) -- line with error

Am I supposed to use Lerp or should I use something else?

reloadcf is nil, it doesn’t exist

Would it be possible to play the CFrame animation if it’s in a table?