How would I start a table trading system?

I wanna make a trading system but most tutorials are about trading tools but my game works on storing data through tables and strings in those tables (hopefully that makes sense). Anyways, I don’t really know how to go about this since there are so many factors to consider like how would I handle duplicates in the players owned stuff table (they’re all string values so idk how to differentiate them) or avoid duping glitches, etc. Any tutorials or posts or just advice to get me started (or maybe even some sample code :wink: jk) Any help is appreciated, thanks!

1 Like

For a simple and rugged trading system, you will need a few things:

  1. Session locking - Session locking is a solution to dealing with the race condition between loading and saving data with DataStore API calls, when for instance, loading data is faster than the data being saved in a time frame despite saving data being first.

This ensures you will not have multiple reads/writes going at once.

  1. Item tracking - utilize a method for creating & serializing the item along with corresponding metadata about the item: UUID (HttpService:GenerateGuid()), CreatedBy (Player), CreatedDate (DateTime.now()).

This will give you information to help you identify this item from every other item in the game, and give you some valuable information that you can use for your own purposes.

  1. Preventing Duplication - UUID checks and trade monitoring (Discord Webhooks?)

  2. A safe method for trading - Both parties are able and willing to trade. Ensured by utilizing server side checks.

I recommend ProfileService to help with session locking and intuitive data storage:
https://madstudioroblox.github.io/ProfileService/

For the data tracking, I recommend using a special registry class from which every item which will be traded is extended from:

local Registry = {}
Registry.__index = Registry

local HttpService = game:GetService("HttpService")

function Registry.new(player: Player)
    local self = setmetatable({}, Registry)

    self.UUID = HttpService:GenerateGUID(false)
    self.CreatedBy = player.Name
    self.CreatedDate = tostring(DateTime.now():FormatUniversalTime("LLLL", "en-us"))

    return self
end

function Registry:Destroy()
    self.UUID = nil
    self.CreatedBy = nil
    self.CreatedDate = nil
end

return Registry

Let me know if you have any questions! Happy trading!

4 Likes