LayerCollector is the superclass of ScreenGuis. In abstract problems I refer to them as LayerCollectors rather than explicitly as ScreenGuis because the issue can be experienced with LayerCollectors as a whole (ScreenGuis, SurfaceGuis, BillboardGuis and PluginGuis) - changing the class wouldn’t change the problem. I find it easier to refer to them via catch-all terminology.
To address this; it’s very much a sanity issue. Like I said in my original post, there isn’t anything wrong with having a LocalScript under StarterGui, but it’s bad practice and terrible for organisation.
Anything under StarterGui automatically gets flushed on respawn. With Guis, you have explicit control over whether this happens or not.
When scripting a UI, your code shouldn’t be in a location unassociated with the object you’re scripting. You wouldn’t put Gui code in the Backpack and you wouldn’t handle character sound scripts from a script directly descending the Workspace (legacy method of putting logic in games before the advent of ServerScriptService).
Why would you want to do this in the first place? There’s no reason to.
Whatever reason you have for handling Gui code this way, it’s probably a band-aid solution. Band-aid solutions are not proper fixes to issues. Band-aids can come off.
StarterGui is not a proper container for client-side logic. PlayerScripts superseded it. Just because code under StarterGui runs, doesn’t mean you should disorganise your code for the sake of something working. Find a proper fix to your issue.
I don’t think truncating the code and sending it to you will replicate the error because the code works fine for me too. This error occurs only started when I put it in a subplace of the game. Maybe you could try that and see if it reproduces.
What subplace do you recommend I move it to, or how is the Gui added to the PlayerGui? The repro I created had everything created under StarterGui, so the circumstances between my repro and what’s happening in your game not be properly aligned.
Subplace as in the universes feature thing
I added the gui through the regular StarterGui method. The code should work fine in the Start Place, but games in the Other Places tab get the error in OP
You’re certain that the versions of the Gui exist similarly between the Start Place and other subplaces? I’m not sure what to say - that truly is a strange issue. There’s clearly nothing wrong with it but the script says otherwise regarding the ancestry.
Have you perhaps considered changing the way your Gui is scripted or where things are placed? Obviously it’s not a proper solution to the problem but it’ll be able to fix the error at the very least if done right; two birds with one stone - better organisation and accessibility (your LocalScript directly descends the LayerCollector as opposed to mounds of frames) and potentially the eradication of that error.
I just checked and they are exactly the same. It’s definitely weird and maybe could be considered a bug for subgames. I’ll change the way the GUIs are scripted. By LayerCollector you mean the StarterGui right?
Yeah. LayerCollector refers to the superclass of the StarterGui.
I figure that if an incomprehensible error like this can’t be figured out, then an appropriate alternative would be to change how your Gui is coded. Placing LocalScripts under the ScreenGui itself should void such ancestry issues, since it’d only have to rely on the ScreenGui being parented to the PlayerGui to be able to function appropriately.
Something slightly off-topic, but related
If you’re feeling like taking an adventure into deep waters regarding Gui creation (and your UI is reactive), you can take a look at the Roact library. I’ve personally never used it before, though I have considered taking a look. I think it’s supposed to simply Gui creation, or something.