Currently, my main data handling script gets a player’s data, and then sends it out to other scripts via a BindableEvent, while the other scripts do an Event:Wait() on the BindableEvent on their onPlayerAdded functions to receive the data and then do stuff from there. But, I feel like this could become a problem when a lot of players join really fast, with the scripts waiting for the event to fire (it would be rapidly firing at that point) and potentially loading the wrong data to a player. Is this a bad idea? Is there any way to fix this without changing my entire data framework? If it is, I will go through the stress of having everything in one script to make sure everything goes procedurally.
Perhaps you may be able to use modules and call a specific function in those modules to execute whatever you need to do once the player’s data is ready. For example:
-- Data Handler
-- Modules
local module1 = require() -- Module Path
-- (After you have retrieved the player's data)
module1.dataRetreived(data)
-- Module
local module = {}
function module.dataRetreived(data)
-- Do stuff
end
return module
I’m not sure if this is what you were asking for but this is what I do.
So you have all of your functions that initialize data in the module? How would you get it to the scope of the script that needs it though, like for example, say you have a table that you’re caching information in (like inventories). If the module initializes the data, you would have to do all the other handling like when a player leaves at that section in the module too? Unless you were using some sort of bindable to send data to another scripts.
Like for example let’s say you have this situation:
local t = {}
On playerAddeds each player gets their own entry to t. If you handle that in the module, the actual script that does the main handling of t wouldn’t have access to it unless you send the data over or do all of it in the same script
Actually I think I fixed this problem. Thanks for the help