Hey guys I made a module script named Player:
local Inventory = require(game.ServerScriptService.PlayerData.Inventory.Inventory)
local Player = {}
Player.__index = Player
function Player.new()
local NewPlayer = setmetatable({}, Player)
NewPlayer.Inventory = nil
NewPlayer.Stats = nil
return NewPlayer
end
function Player:SetInventory(inventory)
self.Inventory = inventory
end
function Player:GetInventory()
return self.Inventory
end
function Player:SetStats(stats)
self.Stats = stats
end
function Player:GetStats()
return self.Stats
end
return Player
I required the module script in a script called Main:
local Players = script.Parent.Players
local Player = script.Parent.Player
local Stats = script.Parent.PlayerData.Stats
local Inventory = script.Parent.PlayerData.Inventory
function PlayerJoined(player)
local ID = "player_"..player.UserId
-- Creates a player and stores the info in the module script Players.
local NewPlayer = Player.new()
NewPlayer:SetStats(Stats)
NewPlayer:SetInventory(Inventory)
Players[ID] = NewPlayer
end
game.Players.PlayerAdded:Connect(PlayerJoined)
I was wondering why when I say this in the main script:
local NewPlayer = Player.new()
It gives me an error that says "new is not a valid member of modulescript". I've done this a thousand times so I was just wondering what I'm not seeing right now lol.
Thank you!
SOLUTION: I forgot to require it cause I'm dumb.

6 comments
Have you tried using :WaitForChild() ? Sometimes the server loads slower.
You can't use the require function in a module script
Yes you can @CreationNation1
You are not requiring it,you need to do this
local yourModule = require(path_to_module)You are not requiring it,you need to do this
local yourModule = require(path_to_module)You can, I'm just dumb and didn't require them. I just put the path for some reason lol.