Player stats being mixed up. module usage wrong?

i have a game with a combat system, and all the player stats are stored in a module.

here’s what a server of 4 people would look like in the module

module = {
     ["player1"] = {
          inventory = {},
          states = {},
          cooldowns = {},
          fightingstyle = "none",
          index = {}
     },
     ["player2"] = {
          inventory = {},
          states = {},
          cooldowns = {},
          fightingstyle = "none",
          index = {}
     },
     ["player3"] = {
          inventory = {},
          states = {},
          cooldowns = {},
          fightingstyle = "none",
          index = {}
     },
     ["player4"] = {
          inventory = {},
          states = {},
          cooldowns = {},
          fightingstyle = "none",
          index = {}
     }
}

of course all their stats are random and the tables are full.
one thing that i’m not sure is ok is that i have functions in that same table with the other player’s stats.

idk if that causes the issue i’m having which is player’s stats randomly being mixed up, and having other people’s stats for what it seemed to be. so i’m curious if i’m using a modulescript wrong, or i would have to look into it more

You can have keys/fields which point to function values within table values, i.e;

local functionTable = {
	["print"] = function(...)
		local args = {...}
		print(table.unpack(args))
	end,
	
	["warn"] = function(...)
		local args = {...}
		warn(table.unpack(args))
	end,
}

functionTable.print("Hello world!")
functionTable.warn("Hello world!")
1 Like