Accessing module table from server script

Hello,

I have created a module script to handle assigning players to a table based on team. I have required the module in my server script but am having trouble accessing the team tables from the module script. When i try to access the module script tables from the server script they return nil.

ModuleScript:

local PlayerManager = {}

local Players = game:GetService("Players")

local assignX = false

teamX = {}
teamO = {}

local function assignTeams(player)
	if not assignX then 
		table.insert(teamO, player.Name)
		assignX = true
	else
		table.insert(teamX, player.Name)
		assignX = false
	end
	print("Team O: ".. table.concat(teamO, ","))
	print("Team X: ".. table.concat(teamX, ","))
end

Players.PlayerAdded:Connect(assignTeams)

return PlayerManager

ServerScript:

local PlayerManager = require(Modules.PlayerManager)

I’ve tried several syntax with no success.
Ex.

PlayerManager.teamX

PlayerManager[teamX]

playerManager["teamX"]

What am i missing here?

I’ve had a similar issue before. I think I either fixed it by defining the tables like this:

PlayerManager.teamX = {}
PlayerManager.team0 = {}

or by storing the tables as folder instances

1 Like

That worked! Thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.