Attempt to call nil value, Module script

Server Script:

local module = require(game.ReplicatedStorage.ModuleScript);

module.UserData["Player Settings"].insert(module.UserData["Player Settings"], 1, true);

print(module.UserData["Player Settings"]);

Module script:


return {
	UserData = {
		["Knife Skins"] = {},
		["Player Settings"] = {},
		["Crafts"] = {},
		["Knives"] = {},
	},
	GameData = {}
}

Error:

  10:19:08.767  ServerScriptService.Script:3: attempt to call a nil value  -  Server - Script:3

What is the problem?

insert doesn’t work that way.
table.insert(module.UserData["Player Settings"], 1, true)
or
module.UserData["Player Settings"][1] = true
You probably want the second one since order seems to matter in a settings file, but of course I don’t know exactly how you are implementing this.

2 Likes

This was just for practicing modules, is using return table a good practice?

It doesn’t especially matter, it’s up to your preference. Whatever you think looks cleaner or more organized.

1 Like