Hello, so.. i use global variables for all the player's data, with a dictionary:
_G.data = {} game.Players.PlayerAdded:Connect(function(player) _G.data[player.userId] = UserData:GetAsync(tostring(player.userId)) or { money = 0, lvl = 0, xp = 0, stage = 1 } end)
everything is in this global variable, but i want to know if it's good to use or sometime it'll break. and if it does break sometimes, should i use Bindable Events to call the data?
something like
in main:
data = {} game.Players.PlayerAdded:Connect(function(player)] data[player.userId] = UserData:GetAsync(tostring(player.userId)) or { money = 0, lvl = 0, xp = 0, stage = 1 } end) events:WaitForChild("getData").OnServerInvoke = function(player) return data[player.userId] end
in some script:
local data = events:WaitForChild("getData").InvokeServer(player) ...
Well using _G will take longer than using things returned by a module.
Tomarty explains this better on devforum here
ModuleScripts are reportedly faster than using global variables and more efficient too, since global variables can only be accessed by the basic type of scripts however modules can be access by any script