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

1 comment
It's a place created from the create place api, so not all players will join the game exactly at the same time, so I made it that as soon as they have a stat to record, it will add them to the table. Unfortunately, that's not really an answer to my issue since it doesn't affect the reason why it is acting the way it is.