How would I set the rotation to none in a folder?

I know I have posted yesterday but I am stuck again smh

I don’t know how to word the title, but I want all models rotation to be set to 0,0,0. I have this script:

local children = workspace.trees:GetChildren()
local CF = children:GetPrimaryPartCFrame()
for i = 1, #children do
	children:SetPrimaryPartCFrame(CFrame.new(CF.Position))
end

Line 2 is the problem:

attempt to call a nil value

I assume that It is trying to get primary part cframe, but it has a primary part. It is a mesh so that maybe the problem ? I tried to set it to normal parts but same problem

1 Like

You’re using SetPrimaryPartCFrame on a table, I think you meant to do this

local children = workspace.trees:GetChildren()
for _, model in pairs(children) do
	if model.ClassName ~= "Model" or not model.PrimaryPart then
		continue
	end
	model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.Position))
end

And a numerical for loop method incase needed

local children = workspace.trees:GetChildren()

for i = 1, #children do
	local model = children[i]
	if model.ClassName ~= "Model" or not model.PrimaryPart then
		continue
	end
	model:SetPrimaryPartCFrame(CFrame.new(model.PrimaryPart.Position))
end
1 Like

Glad my problems are at least easy to fix, thank you

1 Like

You have to do locaal CF = children[i]:GetPrimaryPartCFrame()
you are currently trying to get the CFrame of a table.

1 Like

You are missing one thing [1]

Sorry for no formatting as i am in mobile

local children = workspace.trees:GetChildren() local CF = children:GetPrimaryPartCFrame() for i = 1, #children do children[1]:SetPrimaryPartCFrame(CFrame.new(CF.Position)) end

@EmbatTheHybrid showed you how to do it with pairs but in general i stick with the for i = 1, # method as it relates more to normal arrays

To my credit, I haven’t used these functions or events (I don’t know what they’re called) before

simply add 4 spaces

did this on mobile
if true then
    print(“ok”)
end