I’ve been trying to make an inventory system using OOP and module scripts, but I’m not sure how I would get the information to set up the gui on the client.
e.g
-- Module script
local inventory = {}
inventory.__index = inventory
function inventory.new(player) -- Created on the server
local self = setmetatable({}, inventory)
self.Backpack = {}
self.Hotbar = {}
self.Player = player
return self
end
Would I use a remote function to get the server object every time the inventory is updated?
What would be the easiest way to do this?
Yep, tbh all you need is the data as you said Backpack, and the Hotbar just the properties.
And that’s fine as you probably want the server sided object to be different from the client sided one. Some people use Run service:Is server to handle this. One example is a save function in the server one and gui, input, and get data from server in the client one.
Similar to this:
But is OOP worth it? IDK just make it modular and prepare for the inevitable reworks and changes it will go through. If each function does only one thing with a single responsibility principle style then it shouldn’t be too difficult to fix up later on.
Just saying cause I made some mistakes in the past with it like having to look at multiple module scripts to see what a simple object does due to inheritance in a scenario where it’s not needed.