Roblox CFrame expected, got Vector3.new()

Hi, I’m trying to rotate my pets to a certain object however only 1 out of the 4 pets rotated in the desired direction. I noticed the 2nd pet needs to rotate 90 degrees to reach the desired direction, the 3rd needs to rotate 180 degrees and the 4th needs to rotate 270 degrees. However I’ve been getting this error: CFrame expected, got Vector3.new()

error line:

pet:SetPrimaryPartCFrame(CFrame.new(pet.PrimaryPart.Position + CFrame.Angles(math.rad(index*90),0,0),coin.Position))

Thanks in advance!

for _, petInTable in pairs(petsEquippedTable) do
			for i, pet in pairs(character:GetChildren()) do 
				if pet.Name == petInTable then
					
					local index = 0
				
					
					local angle = circle / MAX_PETS * i
					local x_pos = math.cos(angle) * radius
					local y_pos = math.sin(angle) * radius
					local attachmentCoin = Instance.new("Attachment",coin)
					attachmentCoin.Position = Vector3.new(x_pos, 1, y_pos)
					attachmentCoin.Visible = false

					local alignPosPet = pet:FindFirstChild("AlignPosition")
					alignPosPet.Attachment1 = attachmentCoin
					local alignOrPet = pet:FindFirstChild("AlignOrientation")
					alignOrPet.Attachment1 = attachmentCoin
					
					pet:SetPrimaryPartCFrame(CFrame.new(pet.PrimaryPart.Position + CFrame.Angles(math.rad(index*90),0,0),coin.Position))
					index+=1
					
				end
			end
1 Like

The error line has .Position, it should be .CFrame (twice).

Didn’t work, now the error is: Vector3 expected, got CFrame

Actually, remove your CFrame.new inside the SetPrimaryPartCFrame. And replace .Position with .CFrame.

I’m using the LookAt function inside the SetPrimaryPartCFrame, maybe that’s why it’s only taking Vector 3 arguemnts? Still didn’t work though.

I don’t see this line.
30 c bypass

Well I’m not actually using the LookAt() function because there is none within a model. This is how you change the .LookAt CFrame of a model which I am using:

Model:SetPrimaryPartCFrame(CFrame.new(Model.PrimaryPart.Position, position_to_look_at))

You’re trying to add a CFrame to a Vector3 in the first argument of CFrame.new()

This should work:

pet:SetPrimaryPartCFrame(CFrame.new((pet.PrimaryPart.CFrame * CFrame.Angles(math.rad(index*90),0,0)).Position, coin.Position))

pet:SetPrimaryPartCFrame(CFrame.new(pet.PrimaryPart.Position,coin.Position) * CFrame.Angles(math.rad(index*90))
1 Like

Try

pet:SetPrimaryPartCFrame(Vector3.new(pet.PrimaryPart.Position + CFrame.Angles(math.rad(index*90),0,0),coin.Position))
or

pet:SetPrimaryPartCFrame(Vector3.new(pet.PrimaryPart.CFrame+ CFrame.Angles(math.rad(index*90),0,0),coin.Position))

Oh, I’ve figured it out, you put the index as 0 each time it goes around so it keeps resetting to 0, forget my previous post. Hope this helps!