Most efficient way to make an inventory system?

I’m making an inventory system, and I want it to have some security so that players cannot just add items to their inventory. What is the best way to store the inventory data on the server, to compare it on the client and replicate correctly? Two ideas I have is folders and values in ReplicatedStorage, but that may be laggy. Another idea is a table in a script, but that would involve a lot of remote events and functions mumbo jumbo instead of automatic replication. I want to make this system good so that I don’t have to go back and re-make it later.

Edit: I was hoping for more of a discussion here instead of an exact solution, just to get some ideas on my inventory system. Since I have already created it I’m just gonna mark the most helpful comment for me as the solution so this isn’t bumped further.

3 Likes

I just store inventory data under the player folder, not like they can actually change it from the server.

Robloxs backpack is like this too.

1 Like

You shouldn’t be really concerned that some genius will enter your game and start filling their inventory with all your tools.

The best advice I can give is never trust the user. They pulled out a sword, well, did they? Do you have record of giving them said sword?

Just allow the inventory to store images of any weapon without restriction, including all needed information (levels of tools, the tools itself, etc) that a client should be able to do. Then, while they attempt to use a tool their inventory displays as owned by them, fire a remote to test if you logged, on the server, the user obtaining said tool before giving them it.

1 Like

Yeah, that’s what I was gonna do, but I would still have to keep record on the server each item the player has. I may use @MalosVindictus’s suggestion because that seems best. It’s how gear and leaderstats are used, and those are usually secure.

1 Like

I was more looking for an explanation of how to store inventory data on the server and replicate that as efficiently and lag-free as possible. I don’t feel like watching a 1 hour video for that, but I appreciate you replying

If you want to replicate it to the client then only send the data through a remote event at specific times e.g when they gain an item.

1 Like

Basically to make an invetory system you use serialization.

Here is the topic. How to save parts, and the idea of Serialization

You make this into a Module. Create a Script as it parent. To encrypt the inventory information to one piece of string. Therefore, you make a Inventory folder under PlayerGui, or Character. When player collect something put the item in there…

As long as all of the inventory items are parts or decals they should save if you do a simple command in the script like;

local serializationModule = require(ServerScriptService.serializationModule)
local remoteEventCreateCharacter = game:GetService("ReplicatedStorage").remoteEventCreateCharacter
local DataStoreService = game:GetService("DataStoreService")
local InventoryStore = DataStoreService:GetDataStore("PlayerInventory")

remoteEventCreateCharacter.OnServerEvent:Connect(Function(player)

local ecryptedData = serializationModule.Encode(player.PlayerGui:FindFirstChild("Inventory"):GetChildren())




     
    local success, errorMessage = pcall(function()
    	InventoryStore:SetAsync(player.UserId, ecryptedData)
    end)
    if not success then
    	print(errorMessage)
    end



end)



2 Likes

You should have save data on everything a player owns… how else would they buy a new item or get endgame gear, etc? Do they just spawn with everything?

yeah you can you the items Position values and change them to the amout of items you own since they don’t matter since you can’t see them

Did you reply to the wrong person because nothing you said made sense?

I’m asking OP on how keeping record of owned tools on the server is an extra task when saving data already accomplishes this task. Considering you need to save what tools a player owns to give them what they earned