Invalid argument #1 (CFrame expected, got nil)

Trying to make something Spin but it keeps giving me this error.
image

Code:

local SpinAmount = 0.1
local YellowCoin = game.Workspace.Coins.YellowCoin.Coins:GetChildren()
while wait(0.01) do
	YellowCoin.CFrame = YellowCoin.CFrame * CFrame.Angles(0, SpinAmount, 0)
end

Any help?

Is the yellowcoin a model?
It seems to be argument 1 that’s nil

Yeah the Yellowcoin is a model
Confused, can’t you do CFrame with grouped parts?

1 Like

Yellowcoin doesn’t have CFrame, you could use a part from inside the model or Yellowcoin.PrimaryPart
if you have a primary part selected

3 Likes

Alright
Try this.

local SpinAmount = 0.1
local YellowCoin = game.Workspace.Coins.YellowCoin.Coins:GetChildren()
while wait(0.01) do
	for i, v in pairs(YellowCoin) do
		v.CFrame = v.CFrame * CFrame.Angles(0, SpinAmount, 0)
	end
end

You’re getting a table of the instances contained in the Coins folder, so you need to loop through them and apply the changes to the items not the folder

1 Like

If it’s a model then set a primary part then spin it using Model:SetPrimaryPartCFrame():

local SpinAmount = 0.1
local YellowCoin = game.Workspace.Coins.YellowCoin.Coins
while wait(0.01) do
	YellowCoin:SetPrimaryPartCFrame(YellowCoin.PrimaryPart.CFrame * CFrame.Angles(0, SpinAmount, 0))
end
2 Likes

If it is a model use this script

Got an error
image

You need to set a primary part first (Model.PrimaryPart). Mega lazy approach:

local SpinAmount = 0.1
local YellowCoin = game.Workspace.Coins.YellowCoin.Coins
YellowCoin.PrimaryPart = YellowCoin:GetChildren()[1]
...

Although you’d probably be better off manually setting it. Also that wouldn’t work if GetChildren() returned something that wasn’t a BasePart.

2 Likes