Hello, I’m having a issue in studio, when testing (pressing play or starting a local server) my game only about 60% of the time loads the modules required by asset ID. I get no error messages or anything just a game missing a few features.
I have an initialize function in each module that sets things up (changes locations of scripts, enables scripts, and makes some new instances) and is called first thing from a manager script. It appears that the modules do work but certain things don’t. I believe a few lines of code are skipped in the manager script due to loading priorities.
When loaded properly:
Client sees interaction text, server updates that text, interaction works with key press
When loaded improperly:
Server seems to preform fine, but not the client visuals, interaction only works if using click detector
How can I ensure that 100% of the time my linked modules fully load and initialize? Why is this happening?
For clarification:
I published and own all the module asset ID I’m referring to
I have print messages at the end of each module that shows something in the output once loaded
you can use the content provider service:PreloadAsync(), which takes an array instances to be preloaded, thus ensuring assets are always loaded in. However, note that this is a yielding function, meaning that it will stop the execution of the following lines in the current thread. If you want to avoid this you can use coroutines.
Does this only happen directly after the player loads into the game? If so, you may want to try storing client-side assets in ReplicatedFirst (if you aren’t doing so already).
PreloadAsync is only valid for assets that need to be downloaded. That mostly pertains to content ids (TextureId, ImageId, MeshId, so on). Module scripts do not need to be downloaded, therefore feeding them through PreloadAsync is pointless.
@Nightcaller Is there a specific reason you’re requiring by AssetId? Why not have the ModuleScript available in your game? If you need it to be consistent amongst multiple games, you could make the ModuleScript itself a package.
Is it possible that your modules have bumped into some kind of infinite yielding? Try requiring modules by placing the ModuleScripts parented to the script and require them and test if the results are the same or different.
This does seem to be the result of the load timing with the players. If the player loads first then the client misses important stuff. When the client loads after initialization the client gets the stuff.
I’m only putting stuff into the replicated storage, and not the replicated first. I think the issue will persist even with replicated first
Result
Scenario1
Timing
Server Task
Client Task
Note
1
Server Starts
2
Game Script Runs
Client Joins
3
Modules Initialize
Client Obtains Nothing
This is where things break
4
Client Scripts are Ready
Client Scripts are put in ReplicatedStorage, StarterPlayer, StarterGUI
Scenario2
Timing
Server Task
Client Task
Note
1
Server Starts
2
Game Script Runs
3
Modules Initialize
4
Client Scripts are Ready
Client Scripts are put in ReplicatedStorage, StarterPlayer, StarterGUI
@colbert2677 yeah you said it, the specific reason for requiring by AssetId is for consistency among multiple games. So if I find an issue with a feature or I find a better solution I can update the module in a test environment and all the games using that module will catch the updates when new servers load.
I haven’t used packages yet, but they are definitely something on my research list. Is there any benefits of packages vs requiring by asset ID?
I don’t think it’s an issue of infinite yielding because everything works, just the client doesn’t get the updates. Everything seemed to work find when requiring the parent, but I can’t rely on requiring the parent.
I just followed this api refrence to manually load the characters and that seemed to consistently make things work. Then I added some code that delays the character load until initialization finishes.
Everything seems to be in working order now. Thanks!
Packages accomplish what requiring by asset ID does. You can have the ModuleScript available in your game’s hierarchy directly and updates to the ModuleScript are pushed as updates to the package. Every game using an updated copy of the package receives an updated copy of your ModuleScript.
Package release information:
Related topic (as requiring by ID is almost the same as the below):
So instead of a script that requires by ID, you put your ModuleScript directly in your game in the appropriate location you’ll be accessing it from and you require that module. When you update the ModuleScript, you push the updates to the package. Thus, all your games have the updated ModuleScript.