I have tried reading the array variable Players by accessing it like module.Players from an outside script, and I have also had a getStat function which returned Players, however the getStat function (which was inside the module) read the array as empty, even though changeStat reads it as having one entry.
****statService (Module In ServerScriptService)
local module = {} module.Players = {} function checkPlayers(plr) for i = 1,#module.Players do if module.Players[i][1] == plr then return i end end return 0 end module.changeStat = function(player,stat,value) local index = checkPlayers(player.Name) if index == 0 then module.Players[#module.Players+1] = {player.Name,0,0,0,0} --Player Name,K,D,Dm,H index = checkPlayers(player.Name) end module.Players[index][stat] = module.Players[index][stat] + value for a = 1,#module.Players do for b = 1,#module.Players[a] do print(b..": "..module.Players[a][b]) end end end return module
?????? Just do
game.Players:GetPlayers()
..
To any who have issues with Module Scripts and saving data, the issue was me using the command bar to test them. The command bar is at a more elevated environment which causes it's state to be essentially 'saved' when the game is played. This meant that even if I added an element to array, if I tried to access it using the command bar it wouldn't see it.
To counteract this issue, you need to test modules with scripts / local scripts.