What is the best way of making a table for multiple scripts?

So, here I want to make a player table that would work for multiple scripts. An example for it to be used would be, spectate, AFK, etc. Currently, my table is located inside the main game script where it gets the players and starts a round. I was thinking to use a module, but is there any other better options for this kind of thing?

Help would be appreciated, thanks.

Edit: Not to mention I want it to work for both client and server side.

1 Like

Here is what GnomeCode does, he creates a folder in replicated storage and everytime a player joins the round, he adds a “marker” for that player inside the folder. Everytime the player dies, he deletes the marker. He uses string values for the marker as you can insert the player’s name. Once this is created, all you have to do is check the markers to see if a player is in-round etc…

The module would store the table and you can make functions for editing the table. The module will also allow other scripts to grab the table and its contents(If you make a return* function that is) as long as they can require it that is.

There is no better way sadly

you mentioned

You can store the module in SSS and have remote functions return the information to the clients at steady increments. Or during events in which an update is required.

1 Like

What do you mean “better option”, Modules are OP

To answer your question, use a ModuleScript and return a table.

1 Like

Will it save the table whenever changed??? Because I want to get all the players, then teleport them into the game. Then from the client side(spectate), get the table that was just used in the main script and use the players in that table to be only spectated.

There is no need to save. Its updated automatically.
If a player loses(exits/dies in a match) you would just set up a event to detect that then you would just update the table and then notify all clients of the changes

Ok, but I’m new to modules, could you show an example, just the table part?

I believe your module will look a little like this

Example

Example Of how your module might look

local MatchMakingModule = {} -- // Module Name

local PlayerInfo_Example = { --//Example Of What your storing in Table
	AFK = false --// If they will be counted in match start
  	InRound = false --// Any other stats you want
}

local PlayerInfoTable = {} --// Table which u will have 

function MatchMakingModule.ReturnPlayersInfo()
return PlayerInfoTable
end

function MatchMakingModule.Add_Player(Player)
	if Player:IsA("Player") then
		if not PlayersInfo[Player] then
			PlayersInfo[Player] = PlayerInfo_Example 
		else
			warn("Player Already Added")
		end	
	end
end

function MatchMakingModule.Remove_Player(Player)
	if Player:IsA("Player") then
		if PlayersInfo[Player] then
			PlayersInfo[Player] = nil
		else
			warn("Player Already Removed or was never added")
		end		
	end
end

return MatchMakingModule

Thank you so much. You helped me a ton!

1 Like