Help in Inventory system

ModuleScripts are the way to go
Typically you’d have a module on the server that contains each player’s inventory.

local Inventory = {}
local inventories = {}

function Inventory.GetInventory(player)
    return inventories[player]
end

function Inventory.AddPlayer(player, inv)
    inventories[player] = inv
end

function Inventory.RemovePlayer(player)
    inventories[player] = nil
end

return Inventory

Now any code on the server is able to access a player’s inventory

I recommend using a RemoteEvent to update the client on changes to its inventory, and other remotes for the client to use to manipulate its inventory.

local Inventory = require(path.to.module.above)

--code somewhere on the server
EquipEvent.OnServerEvent:Connect(function(player, requestInfo)
    local inv = Inventory.GetInventory(player)
    --run any necessary checks to see if they can equip something
    --change inventory

    InventoryUpdateEvent:FireClient(player, inv)
end)

Any time the client wants do something to its inventory, it fires a relevant RemoteEvent to the server, which will either ignore the request (if it is invalid), or process it

Edit: Here’s an example inventory (you can structure it however you’d like)

{
     Items = {
          {
               Name = "Sword",
               Type = "Weapon",
               State = "NotInUse",
          },
          {
               Name = "Drink",
               Type = "FoodItem",
               State = "UnEaten"
          }
     }
}
15 Likes