Hi, I’m having an issue I have no clue how to research or resolve. I made it so that players inventories are stored inside of a module script. When the player joins the game, a premade module script(I tried doing Instance.new('Modulescript) but it couldn’t be update and couldn’t return anything) is cloned into their Player. Their inventory is loaded after that. The issue Im having is that the module script in the client isn’t the same as the one on server. Doing require(print(…)) on the module returns empty curly brackets while the server one returns the players inventory. Before this wasn’t an issue, but now that I’m getting to making the Gui, the only way I’ve found to show the players inventory is by using a script to update the Gui, and a local script to call a remote event every couple seconds. It’s the only way I’ve been able to access the players inventory. Here’s the data store code with the irrelevant parts removed:
game.Players.PlayerAdded:Connect(function(player)
local playerInventory = script.playerinventory:Clone()
playerInventory.Parent = player
local startingItems = script:WaitForChild('startingitems')
local saveInventoryKey = CederStorage:GetAsync('Player-Inventory-Id:'..player.UserId)
if saveInventoryKey then
local loadPlayerInventory = require(playerInventory)
local loadedItems = saveInventoryKey
for i, item in pairs(loadedItems) do
loadPlayerInventory[i] = item
end
else
for i, startingItem in pairs(startingItems:GetChildren()) do
_L.GenerateNewItem(player, startingItem.Name)
end
end
end)
...
game.Players.PlayerRemoving:Connect(function(player)
local inventoryKey = 'Player-Inventory-Id:'..player.UserId
local itemsToSave = {}
for i, item in pairs(require(player.playerinventory)) do
itemsToSave[i] = item;
end
CederStorage:SetAsync(inventoryKey, itemsToSave)
end)
Local script
local inventoryServerEvent = game.ReplicatedStorage.InteractionRemoteEvents.Inventory
while true do
inventoryServerEvent:FireServer()
wait(2)
end
local ReplicatedStoage = game.ReplicatedStorage.InteractionRemoteEvents
local InventoryEvent = ReplicatedStoage.Inventory
InventoryEvent.OnServerEvent:Connect(function(player)
local playerInventory = require(player.playerinventory)
local playerGui = player.PlayerGui
local inventoryGui = playerGui.ScreenGui.StatisticsGuiHolder.StatisticsGui.StatisticsLabel.InventoryGui.InventoryScroll
local gridDisplay = inventoryGui.GridDisplay
local itemCellTemplate = inventoryGui.Template.ItemCell
for i, item in pairs(playerInventory) do
if gridDisplay:FindFirstChild(i) == nil then
local cellClone = itemCellTemplate:Clone()
cellClone.Name = i
cellClone.Parent = gridDisplay
cellClone.ItemName.Text = item.name
cellClone.Visible = true
if item.amount then
cellClone.ItemAmount.Visible = true
cellClone.ItemAmount.Text = item.amount
end
else
if item.amount then
gridDisplay[i].ItemAmount.Visible = true
gridDisplay[i].ItemAmount.Text = item.amount
end
end
end
end)
Sorry if my code is really sloppy.