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
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
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