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.
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
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.
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.
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
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?
local uiAssets = game.Players.LocalPlayer.PlayerGui:WaitForChild("guiAssets")
local messageFrame = uiAssets:WaitForChild("messageFrame")
local _message,_pName = messageFrame:WaitForChild("message"), messageFrame:WaitForChild("pName")
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.
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?
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).