So I have a Part that when it is Touched
it Clones a Folder with a LocalScript in it into the Player's PlayerGui. To make the function in the LocalScript fire when it is copied, I had an event listener wait for its parent to be changed.
An equivelent example:
function PrintHello() print("Hello") end script.Changed:connect(PrintHello) --note that in my actual script it is actually script.Parent.Changed since the LocalScript is in a folder. Also, my function does more than print.
This worked fine when I tested it in Studio, but when I started a server the function for some reason does not fire (the folder is cloned in fine, though.)
Does anyone know why this is?
I just tested the script you provided for myself and it worked fine for me.
I recommend throwing some extra 'print' commands throughout the script to see exactly what does run, what the values of various things are, etc. Sometimes things aren't fully loaded in Online mode and so the values aren't what you expect.
I find it odd that the script.Changed fires at all (though it definitely did when I was testing); it seems that the script gets run after its .Parent property changes but before the .Changed event fires. If your script waits for anything, it will miss the .Changed event.
Since LocalScripts don't run if they're in ReplicatedStorage (and most of the other locations too; the wiki explains exactly where it can run), if your localscript is in there, just assume that it's ready to go the moment the script starts running.
I'm not exactly sure what exactly what you're asking, but if you are looking for the ancestry of the object firing, use .AncestryChanged
function PrintHello() print("Hello") end script.AncestryChanged:connect(PrintHello) --note that in my actual script it is actually script.Parent.Changed since the LocalScript is in a folder. Also, my function does more than print.