How should I store data from the client

I have a custom inventory GUI that uses the default roblox tools, where players can drag tools to different slots in their inventory to organize. However, this inventory order is all client sided, and I want to save that order when the player leaves the game. The tools themselves are stored on the server inside the player’s backpack. Should I use a remote event to save the player’s inventory order when they leave the game, or is there a better way of going about this?

I’m not super worried about security, as the only thing the client can send over the remote is the order of their inventory. The server checks all the tools they have.

1 Like

I guess you can fire a RemoteEvent with a table containing the orders of items every time you move your items, and (to avoid DataStore spam) save it only once the player leaves.

1 Like

How should I store multiple dictionary tables on a single script on the server? I’m kinda garbage at tables lol

player.Backpack:GetChildren() should return the table of items in the player’s backpack

local t = {["Anything"] = {}, ["Anything2"] = {}}
print(t["Anything"])
-- Or 
local t = {anything = {}, anything2 = {}}
print(t.anything)
1 Like

You can use something like this:

local PlayerInventories = {}

game.ReplicatedStorage.InventoryEvent:Connect(function(Player, Inventory)
if typeof(Inventory) ~= “table” then return end

PlayerInventories[Player] = Inventory
end)

How this will work is you got a single dictionary which holds all players’ inventories. To access a particular player’s inventory you run PlayerInventories[Player] where Player is the player instance and not just the name.

The RemoteEvent will also set the player inventory in the dictionary to what is sent through the RemoteEvent.

2 Likes

I assume that when a player leaves, I have to remove their inventory from the dictionary as well. I’ll test it out. Thanks for the responses!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.