Move all children of a folder

  1. What do you want to achieve? Keep it simple and clear!
    I need all children in a folder (they are models) move

  2. What is the issue? Include screenshots / videos if possible!
    The console says invalid argument #1 (CFrame expected, got table)

	for name, child in pairs(prevRoom.Furniture:GetChildren()) do -- Looping through all of the children
		if child.Name == "LightsWhite" then
		else
			if child.Name == "LightsRed" then else
				for i = 1,10 do
					child:SetPrimaryPartCFrame(CFrame * CFrame.new(0, 0.25, 0))
					wait(0)
				end
			end
		end
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

kinda confused about the layout of it why are you waiting 0 seconds?

oh they arent necessary? 303030

1 Like

you could just do

if child.Name == "LightsWhite" or child.Name == "LightsRed" then
  continue
end
1 Like

thanks, but what about the issue itself? Do you know how to solve it?

1 Like

are you sure it is the CFrame in setPrimaryPart parameter as it is saying it expected a CFrame

2 Likes

It might be this part that is underlined:
image

Is “CFrame” actually a variable? If not, then I’m pretty sure that’s why

3 Likes

You’re trying to index a datatype constructor the incorrect way, also SetPrimaryPartCFrame is now deprecated and should be replaced with PivotTo instead

I would also confirm that the “Models” are actually models so that your code doesn’t accidentally error in case you insert something else, like a BasePart which has different properties

for name, child in pairs(prevRoom.Furniture:GetChildren()) do -- Looping through all of the children
	if child:IsA("Model") then
		if child.Name == "LightsWhite" then
			print("Found Lights White")
		elseif child.Name == "LightsRed" then 
			print("Found Lights Red")
		else
			print("Moving Part")
			for i = 1,10 do
				child:PivotTo(child.PrimaryPart.CFrame * CFrame.new(0, 0.25, 0))
				task.wait()
			end
		end
	end
end	

Keep in mind that you’ll have to reference a PrimaryPart for the model, so that it’s able to be properly moved otherwise it’ll throw back an error

3 Likes

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