Pet trading that cannot duplicate a pet
Invites, a two-column trade window, a two-step confirm with a countdown, a value warning, cooldowns and trade history. Every item is checked again at the swap, both inventories change or neither does, and a DataStore journal repairs a trade if a server dies before the save. Plugs into Hatchwren pets and works with any inventory.
For: Roblox developers adding player-to-player trading to simulators, pet games and RPGs.
See it work: a real trade, recorded from the shipped code
Ava trades a Golden Drake to Ben, and Ben tries the last-second switch
Every step below ran through Trader on the server side of the test harness. The window replays what each call returned.
Ava gives
Ben gives
After the swap
Ava has
FoxPupOwlGolden KittyBen has
KittyBunnyGolden Drake7 pets before, 7 after. Both players' trade history lists it: with Ben, gave 1, got 2.
12 tricks, each tried for real, each refused
| What the client tried | The server's answer | |
|---|---|---|
| Invite yourself | Refused | bad player |
| Offer the same pet twice | Refused | already offered |
| Offer the other player's pet | Refused | not yours |
| Offer a locked pet | Refused | locked |
| Offer an equipped pet | Refused | equipped |
| Send a table instead of an id | Refused | bad item |
| Confirm before both are ready | Refused | not ready |
| Confirm during the countdown | Refused | wait for the countdown |
| Delete the pet after confirming | Refused | items changed |
| Fire Confirm again after the trade closed | Refused | no trade |
| Start a second trade inside the cooldown | Refused | cooldown |
| Spam the invite remote | Refused | slow down |
The server dies after the trade, before either save
Both players rejoin with the save from before the trade. The journal was written first, so trader:Recover(player) applies each side once: 1 trade for Ava, 1 for Ben, and 0 when it runs a second time.
Ava loads (stale save)
Golden DrakeFoxPupAfter Recover
FoxPupOwlGolden KittyBen loads (stale save)
OwlKittyGolden KittyBunnyAfter Recover
KittyBunnyGolden DrakeWhat's inside
| Module | Runs on | What it does | Lines |
|---|---|---|---|
| Trader | Server | The server-side trade system. | 671 |
| TradeSession | Server | One trade between two players, as a small state machine with no Roblox calls in it (so it is easy to test and to read). | 168 |
| Offer | Server | One player's side of a trade. | 127 |
| Swap | Server | The exchange itself. | 91 |
| TradeLog | Server | Trade history, and a write-ahead journal in a DataStore that closes the classic duplication hole (player A's save lands, player B's server dies before theirs does, and the item exists twice). | 270 |
| Adapters | Server | The small bridge between the trade system and wherever your game keeps items. | 211 |
| Values (free) | Shared | What an item is worth, and whether a trade is lopsided. | 90 |
| Policy | Server | Asks Roblox whether this player may trade paid items at all. | 56 |
| RateLimit (free) | Shared | A token bucket per player per action, so a spammed remote costs you nothing. | 68 |
| Signal (free) | Shared | A tiny event object so your UI and systems can react to trades. | 49 |
| Example script | Type | Put it in |
|---|---|---|
| PetTradingConfig | ModuleScript | ReplicatedStorage |
| PetTradingServer | Script | ServerScriptService |
| PetTradingClient | LocalScript | StarterPlayer > StarterPlayerScripts |
Tested like real software
42 automated tests run in a real Luau VM against a Roblox engine mock, on luau-web 1.4.0 (Luau compiled to WebAssembly). They ship in the zip: cd tests && npm install && node run.mjs.
| Spec | Passing | For example |
|---|---|---|
| demo | 1/1 | demo: a recorded trade, the refused tricks and a crash recovery |
| example | 3/3 | example server: two players join with starter pets and trade through the remotes … |
| journal | 10/10 | a trade is written to the journal before items move, and marked saved after the save … |
| parts | 8/8 | RateLimit: bursts pass, sustained spam is refused, tokens refill … |
| session | 4/4 | offering → countdown → confirm → committing … |
| trader | 16/16 | a full trade: invite, accept, offer, ready, countdown, confirm, swap … |
Install in 5 minutes
- Drag
PetTradingKit.rbxmxonto ReplicatedStorage in Roblox Studio. - Drag
PetTradingKitExamples.rbxmxin and move the three scripts to the services above. - Turn on Studio access to API services and press Play.
INSTALL.mdwalks through an example place step by step.
FAQ
Is this allowed on Roblox?
Yes. It's ordinary Luau using Roblox's own services (DataStoreService, MarketplaceService, Players). Nothing bypasses Roblox rules.
Why not a free model from the Toolbox?
Free models are a fine start. Pet Trading Kit ships its tests (42 of them, run in a real Luau VM), validates every remote argument, and is original code with a clear licence.
Do I need Rojo?
No. Drag the .rbxmx files into Roblox Studio. A Rojo project file is included if you use it.
Can I use it in a game I sell or a client's game?
Yes: unlimited experiences, commercial or not, for you or your clients. You can't resell or share the code itself.
Is CyberMax affiliated with Roblox?
No. Roblox and Roblox Studio are trademarks of Roblox Corporation, named only to describe compatibility.
More tested kits
Free: the Roblox Starter Kit
7 free Luau modules (damage, pets, shop formatting, admin audit log, tycoon guards and more) plus 3 free calculators, then 5 short emails with the scripting fixes we see go wrong most often.