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.
You forgot to require the ModuleScript on line 2 of your main script. Change local Player = script.Parent.Player
to local Player = require(script.Parent:WaitForChild("Player"))
.