I’ve attached a repro file.
This is only a bug in online mode or in server-test-mode client as far as I know
Setting a frame in a PlayerGui’s parent to nil after both the child and the parent have loaded also sets all of the frame’s children to nil.
The following code reproduces the same glitch with several different parameters.
-- Parent/Unparent child is gone! Poof!
do
local Frame = script.Parent:WaitForChild("Frame")
Frame:WaitForChild("Child") -- Guarantees replication
Frame.Parent = nil
Frame.Parent = script.Parent
print(Frame.Child)
end
-- See if memory affects it
do
local Frame = script.Parent:WaitForChild("Frame")
Frame:WaitForChild("Child") -- Guarantees replication
local Child = Frame.Child -- Store in memory
print(Frame.Child) --> Child
Frame.Parent = nil
print(Child.Parent) --> nil
-- Expected Output: Frame
print(Frame.Child) --> ERROR: Child is not a valid member of Frame
end
-- Original repro:
do
local Frame = script.Parent:WaitForChild("Frame")
Frame:WaitForChild("Child") -- Guarantees replication
print(Frame.Child) --> Child
Frame.Parent = nil
print(Frame.Child) --> ERROR
end
Where the following structure is occurs:
[code]
Structured as:
ClassName|Name
PlayerGui|PlayerGui
LocalScript|LocalScript
Frame|Frame2
Frame|Child2[/code]
Setup
[list=1]
[]Open up ROBLOX studio
[]Insert a ScreenGui into the PlayerGui
[]Inside of the ScreenGui insert a frame and a local script
[]Set the local scripts source to the repro above
[*]Inside of the frame insert another frame and name it “Child”
[/list]
Repro
[list=1]
[*]Launch ROBLOX studio in solo test mode. The script prints out
Child
Child
Frame
Child
[]Launch a server with one client
[]The script prints out
[/list]
16:03:58.384 - Child is not a valid member of Frame
16:03:58.385 - Script 'Players.Player1.PlayerGui.ScreenGui.Repro', Line 9
16:03:58.385 - Stack End
Notes
It doesn’t matter if the child is in Lua memory or not, as demonstrated by the repro above.
The expected behavior is that the Frame maintains its children-parent hierarchy even when parented to nil. I’ve been using this to cut down on rendering and event costs when I have a template.
I suspect this error has to do with the latest update where :WaitForChild() now works on non-data-child parented objects. Ironically, it never loads the child.
Setting the parent back to the data model does not reset the children into existing.