How to Implement a RAP (Recent Auction Prices) System?

Hello guyz!

I’m trying to make a system like the RAP (Recent Auction Prices) thing in Pet Sim X/99 for my game. Basically, I want to show players the average recent sale price of items in my game. Sounds simple enough, but I’m running into some questions about the best way to do it.

I’m okay with Lua, but DataStores and optimization are not my strongest areas. Any examples or advice would be HUGE. Especially interested in good data structures (tables, arrays, etc.) and ways to minimize DataStore calls.

Specific questions I have :

  • What data structure would be best for storing the sales history? (e.g., table, array, ordered datastore)
  • What’s the most performant way to calculate the average of the recent sales data?
  • How can I minimize the number of datastore calls to reduce lag and improve performance?
  • Are there any existing Roblox APIs or modules that could help with this implementation?

Any help is super appreciated!

i wouldnt use datastores for this, instead id opt to use memory stores and possibly messaging service if you want the most recent purchases

i personally dont know what pet sim X auction prices systems looks like so im just going off what you said and what makes sense, you can send me some more context if you’d like and i’d be happy to help

Okay, so these screenshots are from Pets Go (Newest BIG Games game)

the first picture shows my pet inventory. When I mouse over a pet, I can see its stats, and importantly, its RAP. so that 25.3k means that’s about how much that specific Storm Dragon has been selling for lately in the auction house. Gives me a good idea of what it’s worth.

The second pic shows someone else’s booth (like pls donate). They’re selling pets for the prices they chose (7k, 6k, 500). Those prices aren’t the RAP, but they affect the RAP. See, when someone buys one of those pets, the price they paid gets recorded. The game then uses a bunch of those recent sales to calculate the average, which becomes the RAP.

EXAMPLE:
if someone buys that pet for 7k and the RAP of the pet is 5k, the RAP for that kind of pet will go up a bit.

[Edit : RAP is the same across all servers, so it’s not just based on what’s happening on my server.]

I’d recommend using memory service, save the price it was sold for in memory service, and check through, lets say the last 100 values, and average them

If you want it to update realtime, you can do that every few minutes or just use messaging service