When a player joins, .createInventory()
gets called and then inserts the player’s name as an index and makes it hold another table.
local ServerInventoryManager = {}
local HandledItems = {}
function ServerInventoryManager.createInventory(player: Player)
local inventoryFolder = Instance.new("Folder")
inventoryFolder.Name = "Inventory"
inventoryFolder.Parent = player
HandledItems[player.Name] = {}
end
But when I run this manually inside the server, it prints out an empty table even though the table has already been initialized and already has a value inside it because as soon as a player joins .createInventory()
gets called.
require(game.ServerScriptService.Modules.Managers.ServerInventoryManager).newItem(game.Players.Hanselkek, "SwordFighter", 1)
function ServerInventoryManager.newItem(player: Player, itemName: string, initialValue: number?)
local inventory = player:FindFirstChild("Inventory")
if inventory then
-- making values...
--problem
local playerItems = HandledItems[player.Name]
print(HandledItems) -- {} prints out an empty table.
print(playerItems) -- nil
if playerItems then
playerItems[guid] = newItem
end
end
end