I work with Aero Game Framework and I’ve encountered an issue that I can’t quite understand. My code warns me that an infinite yield has been detected if I use an in-scope variable but not for an upvalue.
In Aero, each service has an Init method. This method is called when the internal bootstrapper sets things up and is ready to run through each service. Since I don’t use ServerScriptService except to fetch the ChatServiceRunner, I decided to move it into my Init function.
-- Barebones excerpt of my code function ChatSetupService:Init() local ServerScriptService = game:GetService("ServerScriptService") -- Other setup code here local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService) end
For some reason, setting up my function like this warns me of an infinite yield. On the other hand, if I define ServerScriptService outside of the function, that isn’t the case.
-- Barebones excerpt of my code, once again local ServerScriptService = game:GetService("ServerScriptService") -- Other code here: adding methods, other constants and variables, so on. function ChatServiceSetup:Init() local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService) end
Is anyone able to explain the behaviour behind this? I wanted to remove the ServerScriptService constant as an upvalue to avoid keeping a reference when I don’t use it except for this one time, but the warning turns me away from doing so.