Clone() not cloning children of Frame

I am cloning a premade frame using a localscript, the script and frame are both in playergui and the frame is visible in explorer when testing on the client and server, yet cloning the frame leads to just the frame being cloned, not it’s children. This breaks my script, what also doesn’t make sense is that this script worked fine in my test place, yet when I bring it over to my game for whatever reason it just stops working.

I’ve checked multiple times if archivable was off for what I was trying to clone and it isn’t, which makes this extremely irritating. I don’t know if this is a bug or if I made a mistake in my code.

What’s not getting cloned:
0ed59e5f7e013663c6bced3489bae5ee

Result of cloning:
5bc0fd43560ab52bd3db79855e2b880d

	local message = messageFrame:Clone()
	for i,v in ipairs(messageFrame:GetChildren()) do -- this was added in an attempt to clone through iteration which STILL did not work
		if not message:FindFirstChild(v.Name) then
		warn(v.Name)
		v:Clone().Parent = message
		end
	end
	message.Parent = workspace -- parenting it to workspace or anything else changed nothing
1 Like

Try doing WaitForChild()

text

1 Like

I tried waitforchild before realizing that it never clones the children, using waitforchild leads to infinite yield. I am already using waitforchild on all of the original frame’s children.

what line are you getting the error in?

	message.Parent = workspace
	message.pName.Text = plrName -- this line
	message.message.Text = msg

The error exists solely because there are 0 children being cloned

Have you tried using pairs intead of ipairs? Maybe the loop isn’t running at all

The loop isn’t running because somehow LUA thinks that the frame has no children when they’re visible on the client through explorer at the very least, so #i = 0.


As you can see archivable is on for everything that is meant to be cloned.
Changing ipairs to pairs didn’t change anything, either.

Cant you just clone the Parent without the for loop?

1 Like

If you check my code that’s exactly what I did. Check the comments on the code.

hmm. Everything should work then.
How are you defining messageFrame? Maybe there’s another frame with the same name or you are just cloning the frame before the objects inside it are added. I would add a task.wait(2) at the beggining for example just to make sure if the issue really is the script

1 Like

There’s not enough information being said to really pinpoint what is happening.
Clone doesn’t just change its behavior overnight. Somewhere else in your code is causing the issue to happen.

This is just a hunch, but it sounds like whatever your messageFrame variable is assigned to has no children. Can you share the code around that variable?

1 Like

This is how it’s defined:

local uiAssets = game.Players.LocalPlayer.PlayerGui:WaitForChild("guiAssets")
local messageFrame = uiAssets:WaitForChild("messageFrame")
local _message,_pName = messageFrame:WaitForChild("message"), messageFrame:WaitForChild("pName")

What gets me is that the cloned messageFrames that are parented to workspace have no children, and never load any children either. The image in this reply is guiAssets, the folder that contains messageFrame and it’s children. There is no other guiAssets or messageFrame.

Also, if the messageFrame had no children I would get an infinite yield from the above part of the script which waits on it’s children.

It looks like you’re not accounting for StreamingEnabled properly. Descendants don’t get immediately added when an ancestor gets added.

You should yield operations until all of your template’s descendants are added (WaitForChild)

This is what is being done, look at my last reply.

Ah I missed that, sorry!

There is another case actually. If you accidentally destroy that instance and still use that variable for cloning, you’ll get an instance with no children.

Is there anywhere in the code that may be potentially doing that? It could even be something that’s completely unrelated.

1 Like

I don’t think this is what’s happening because it’s still visible in explorer on server and client side, I’ve checked other scripts but there’s nothing that would delete anything in that folder, and I don’t use third party scripts so I can rule out malicious scripts.

Ok, in that case I have a few more questions:
How many instances are in messageFrame right before cloning? (#instance:GetDescendants())
How many instances are in messageFrame 1 second after cloning?

Assert _pName. This will help.

Ok, so your messageFrame template instance appears to have no descendants upon being used. This must mean one of these things here:

  • The template was destroyed
  • Somewhere else in your code is modifying this variable

You mentioned this:

Are you ABSOLUTELY sure that the frame you were looking at is actually the template that’s assigned to messageFrame? Try adding an identifiable instance inside of your template as soon as you assign it to messageFrame, and then see if it’s visible under the explorer.

Another thing you can try doing is listening for instance.Destroying on the template, which will tell you when it’s being destroyed (if it’s being destroyed).

2 Likes