Hecc.rbxl (28.7 KB) Basically I created a gui object in StarterGui, inside I created a LocalScript with these lines of code in it:
print(script:GetFullName())
script.Parent.AncestryChanged:Connect(function(child, parent)
if parent.Name == "PlayerGui" then
print("hecc")
end
end)
The LocalScript is enabled, everything is untouched I just added the lines of script in it.
As you can see on the first line I print the full ancestry for the script, because I am aware that this LocalScript will run once it is parented to the PlayerGui.
On the other lines you can see that I simply connect an event to fire once the Ancestry of the script is changed, which apparently fires even though the script precisely prints on the first line that it is already in the PlayerGui.
So in conclusion the script will end up printing both the fully ancestry of the script, saying that the script belongs to the PlayerGui and the second print (âheccâ), stating that the event was fired and the ancestry was changed to the PlayerGui, even though on the first line it already said it belongs to the PlayerGui.
I am really curious if anybody has an idea on this, I will attach a place where you could testrun and see this in action.
You are basically wondering why it prints it out correct because there was no Ancestry Change correct?
If so I think the reason why is because the UI does not fully spawn in? I am just thinking that could be it cuz when I put a wait 10 seconds in the script it does not print the âheccâ showing there was no Ancestry Change.
Although I donât understand why it would print the full name which shows it is already in the player gui if it had not fully spawned in.
Script:
print(script:GetFullName())
wait(10)
script.Parent.AncestryChanged:Connect(function(child, parent)
if parent.Name == "PlayerGui" then
print("hecc")
end
end)
Maybe this is because the print(script:GetFullName()) and AncestryChanged event happened at the exact same time. In fact, when I added wait() between the print statement and the connect function, âheccâ didnât appear, thatâs because the wait() made the AncestryChanged event delayed by a small period, so it didnât fire.
Also, I tried this code:
print(script:GetFullName())
print(os.clock())
script.Parent.AncestryChanged:Connect(function(child, parent)
print(os.clock())
if parent.Name == "PlayerGui" then
print("hecc")
end
print(script:GetFullName())
end)
and the difference in time was 0.64 milliseconds which is very very small. For comparison, a frame is 17 milliseconds.
The AncestryChanged event includes two parameters, child and parent . child refers to the Instance whose Instance.Parent was actually changed. parent refers to this Instance âs new Instance.Parent (You can learn more here AncestryChanged event).
He chose the names child and parent as a convention, he couldâve wrote this:
print(script:GetFullName())
script.Parent.AncestryChanged:Connect(function(foo, bar)
if bar.Name == "PlayerGui" then
print("hecc")
end
end)