I want to find a way to hook into whether or not every script in the place has loaded, and ran just one frame/yielded, on the server. I’m making a module for the purpose of synchronizing data, and it’d be really convenient if I could guarantee that initialization accesses made to it on the server would happen before the client loaded, and attempted to access it.
So information about some way to have guaranteed each script has loaded, or at least generated a thread would be lovely. I’ve checked the API briefly, but didn’t find anything that looked like a guarantee, or way to check if a script has ran yet or not.
I don’t think you’re able to know when a script starts running or a thread is created, this is due to all the scripts when the game starts are compiled to a binary format (thus, unreadable) even if you could access these processes, the names given for such would’ve been randomized (usually hashes) which would be a pain to identify. I’m not sure how Roblox does everything, so I can’t assure you it’s impossible, but it would require a handful of time & research.
The only way I think you could achieve this is by having some sort of global variable in the first line of each script, setting its value to something that would tell your module it has started. However, I understand it might not be convenient to do so.
I don’t need to know when a part of a script is running, just if it’s running at all. I assume that doesn’t change your answer, but in case it does, the script being transferred to binary isn’t a difficulty that would stop what I want to do.
I’ve done some digging and I found something that might help you:
getfenv & setfenv: used to manage global variables (including functions) that were declared globally (without the local keyword). It’s good to mention that these work for each script individually (they call it an environment)
_G: an array shared between all scripts (could be useful to share local script data)
loadstring: you’ve probably seen this one, you can run code in a script runtime
Note: you’ve probably bumped across these, however I think that with both getfenv & _ G you can have a very interesting functionality (like an analysis function) which could work 2 ways (which I can think of)
Plugin: “Inject” a global variable (using _G) in the first line of every script in the game that give you the ability to track if it’s being executed
Module: User using the module would have to manually “inject” this piece of code at the start of their scripts (they want to analyze), but would work generally the same