Module script content isn't the same as the server script output

Hello everyone,

I’m trying to make a player list for the server,

I’m storing the data inside the module script. However, when I print the content of the module script it doesn’t show what is actually inside the module.

Server:

local PlayerService = game:GetService("Players")
local PlayerDataModule = require(game.ServerScriptService.PlayerData)

PlayerService.PlayerAdded:Connect(function(player)
	
	PlayerDataModule.AddPlayer(player)
	
	print(PlayerDataModule.PlayerList)

end)

Module:

local PlayerData = {}

function PlayerData.AddPlayer(player)
	PlayerData.PlayerList[player.Name] = {
		["Inventory"] = {}
	}
end

PlayerData.PlayerList = {
	
}


return PlayerData

the output of the print(PlayerDataModule.PlayerList) would be just a blank table rather then the player name. Am I doing something wrong?

Thats because you’re trying to print the table, not the table’s content.

Loop through the player list table then print the players in the list.

for i, plr in ipairs(PlayerDataModule.PlayerList) do
    print(plr.Name)
end

that doesn’t seem to resolve the issue sadly, thanks for your help

Why didn’t it work? Did it cause an error?

no it didn’t:
here is what I used

for i,v in pairs (PlayerDataModule.PlayerList) do
 print(i,v)
end

the print function doesn’t print anything

You gotta do print(v.Name) not print(i,v) if you’re trying to get the player’s name.

it won’t print it out as well since I’m storing it this way:

PlayerData.PlayerList = {
["PlayerNameHere"] = {
["Invnetory"] = {}
}
}

so adding .Name would only cause an error

if PlayerData.PlayerList[plr.Name] then
   print(PlayerData.PlayerList[plr.Name])
end

You could instead make it say.

function PlayerData.AddPlayer(player)
	PlayerData.PlayerList[player.Name] = {
		["Inventory"] = {}
	}

    return PlayerData['PlayerList']
end

Then for this

That seems to make it appear on the script where I called AddPlayer but other scripts still have blank tables, Thanks for the repaly

Try putting a print statement by printing the PlayerList in the AddPlayer function. Tell me what it prints.

As expected, It prints the list correctly.

have you tried not sending the player? cause the command already send it itself, no need to add it.

PlayerDataModule.AddPlayer(player) ← try removing the player from here

Hmm, I have never encountered an issue like this before. I am sorry I couldn’t help…

1 Like

Well if he does that, then when he passes and argument it will throw an error saying something around the lines “Passed 1 argument but 0 parameters needed” Module’s aren’t like RemoteEvents or some events where they autopass a player.

as @NoraaApple said, if the player wasn’t sent to the function there would be no other way to create it’s own segment in the table (maybe you think the script is a local script and I’m using a remote event?)