Cloning from workspace on client makes cloned object's parent nil

So i have a code that clones all objects from workspace and i want to move then to viewport frame, but it keeps saying me that cloned objects don’t have parent? Here’s code and output screenshot:
image
image

So the thing is when cloned object has parent is says it parent, other way it says no parent. I still can’t understands why, because as you can see the object exists and it’s name too, but parent is nil. Any help would be apprieciated.

all cloned objects are parented to nil by default. you have to parent them manually

Thats the problem, look at next line after print, it should set cloned object parent, but it says that a.Parent is nil. Thats why i ask!

The print() function is being ran before the parent got set?

Look, if i try to set it’s parent it gives me this error:

If the clone function returned nil then how did it manage to print out its parent and name in the first place?

clone didn’t return nil, it returned object but with no parent, i mean, parent is nil as parameter. So, let me explain, object exists and it’s name, but Parent parameter doesn’t, so i can’t set it or either read it, cuz it’s doesn’t exist at all for script.


image

Do you understand what the error message meant? “Attempt to index nil” is when you run the dot operator on something that is nil. You can only run the dot operator on tables(in this case, an instance which is technically a table), but you tried using it on a nil value. That means that the variable a IS nil, therefore the cloned instance doesn’t exist nor does its name.

The only reason why :Clone() would return nil is because the instance you tried to clone is not archivable. Perhaps you should look into that.

As you can see all is Archivable:

At this point, the issue might not be because of the clone function. I would double-check the script that’s responsible for the cloning; try printing out the object that it’s trying to clone and the cloned object and adding a check to make sure the cloned instance actually exists.

Try replace your else statement with this:

else
v:Clone().Parent = script.Parent.ViewPortFrame
end

image

Ayo, thats all. Umh? Why local script don’t see the parts at all…

that was first version of this script, same thing, doesn’t work

Fixed it by changing lines to this:
image

Thanks to @Prototrode and @kboy100 for help. Have a great day!