I wanted to post this in #bug-reports , but that channel is locked to “Regulars” only - and the “Regulars” role cannot be obtained.
TL;DR
When running a Loop from within PlayerGui or Backpack then calling :LoadCharacter() you are creating invisible threads that run forever and still affect runtime environment. Killing the Player does not cause this.
:LoadCharacter() is a necessary feature often used by many admin command modules. It’s also a staple standard in games that do not use custom characters and rely on default ROBLOX ones, and many games cannot function without it.
However when using any loop (even if it has a “return” or “break” fallback!) the code runs forever, never stopping, and ramps up significantly. After running a repro test I managed to multiply the code to run up to 73 times a second after a couple of :LoadCharacter() uses - which is less than ideal.
This happens whenever e.g. a “while true do” or “repeat until” loop is used in a Script or LocalScript located in PlayerGui or StarterPack. While LoadCharacter states that
It also clears the player’s
Backpack
andPlayerGui
(Player | Roblox Creator Documentation)
, it does not actually remove the content, because code is clearly still running, lingering in memory, seemingly parented to itself and continously affecting the environment.
The :LoadCharacter() page has no mention of it possibly causing memory leaks when used with running loops.
Reproduction steps:
- Create a loop in any Script
- Put the Script in StarterGui/StarterPack
- Call :LoadCharacter() from the Server.
The reproduction file clearly shows that while the scripts are apparently cleared, they are still able to produce parts in runtime, and after each LoadCharacter the parts duplicate, and console prints still run.
This is a big problem, because many games rely on :LoadCharacter() for their games to work and many more rely on free provided Admin Commands that make use of :LoadCharacter() to, for example, refresh a player’s Character - thus loading in a second set of loops (that would e.g. check for input updates), slowing down both the Client and the Server.
loadcharacter bug repro.rbxl (29.7 KB)