Bad Practices when using require?

So recently I have been having issues with loading player data in my game and found that it was because requiring my DataStore2 module was yielding the execution of my PlayerAdded event. So I changed the code to require the module inside of the event instead, which seems to work - just feels gross.

Players.PlayerAdded:connect(function(plr)
	print("Loading data for " .. plr.Name)
	local DataStore2 = require(1936396537)
end)

Is requiring a module inside of a PlayerAdded event bad practice? It feels wrong, but I think I need to do this in order to ensure the PlayerAdded event is run as quickly as possible without yielding for the module to load outside of it.

Not really, no… But I do recommend downloading a copy of DS2 and putting it inside your game, then requiring that. The yield was likely due to it downloading the asset.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.