Invalid number of arguments: 6 - SetPrimaryPartCFrame

Error is

Invalid number of arguments: 6 

My script:

script.Parent.SelectedRE.OnServerEvent:Connect(function(hit,mousepos)
	local cln = game.ServerStorage:WaitForChild("NPC"):Clone()
	cln.Parent = workspace
	cln:SetPrimaryPartCFrame(CFrame.new(mousepos.X, mousepos.Y, mousepos.Z, 0, script.Parent.Parent.SpawnSettings.BoxRotation.Value, 0) --[[+ script.Parent.Parent.SpawnSettings.BoxOffset.Value]]) 
end)

Errors on line 4. Mousepos it the mouse.hit.position coming form a clientscript.

Boxrotation value . When player press R on key boarddddd it does rotate but error in setprimarypartcframe
image

I am a bit confused, what is the expected result of this? Currently, you provide 6 arguments to CFrame.new, which is not something it expects, therefore it throws an error due to argument count mismatch. If you want to apply rotation to a CFrame, you could do something like CFrame.new(X, Y, Z) * CFrame.Angles(math.rad(Rotation), 0, 0)

in cframe it says that ther are 6 arguments which are the x,y,zand then the qx,qy,qz


According to the official documentation, it takes 7 arguments, not 6. I still do not understand the goal though, what are you trying to achieve with it? Does the BoxRotation.Value ever change? If so, what’s the minimum & maximum value it can be changed to?

when player press r box rotate vlaue changes also what is the qw argument

This is my line 4 now

	cln:SetPrimaryPartCFrame(CFrame.new(mousepos.X, mousepos.Y, mousepos.Z), 0, script.Parent.Parent.SpawnSettings.BoxRotation.Value, 0,0) 

it does not error but also does not rotate the npc to way the its supposed to

local BoxRotation = script.Parent.Parent.SpawnSettings.BoxRotation

script.Parent.SelectedRE.OnServerEvent:Connect(function(hit,mousepos)
	local cln = game.ServerStorage:WaitForChild("NPC"):Clone()
	cln.Parent = workspace
	cln:PivotTo(CFrame.new(mousepos) * CFrame.Angles(0, math.rad(BoxRotation.Value), 0)) --[[+ script.Parent.Parent.SpawnSettings.BoxOffset.Value]]
end)
2 Likes

attempt to call a nil value error

try again, fixed it already!!!

1 Like

It’s better practice to use :PivotTo() as @ObviouslyGreen has used in the coding example since :SetPrimaryPartCFrame() is now deprecated.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.