Hi, I’m an a developer that making some Roblox games. I searched for this question on the internet, but I didn’t founded any tutorials how can I make the all player’s transactions list. So, can anyone help me? (I’m not too professional in scripting)
What do you mean? We need more detail or you are not getting an answer.
Hello, you could be using Datastores (Data Stores | Documentation - Hub Création Roblox) in order to save each player’s transactions each time he makes one. You can save his transactions in a table, preferably ordered (1,2,3) or with the dates of the transactions as index.
- When the player joins, you load his data (from the datastore).
- You put it in a table, and you send it via a Remote Event (if you want) to the player.
- When the player makes a transaction, you add the transaction to the table (table.insert() for 1,2,3 index).
- When the player leaves, you save the table in the datastore.
Bro, I already know this, but how can I make an list gui + that will show the transactions in 1, 2, 3… order?
- You can use a Scrolling Frame (ScrollingFrame | Documentation - Roblox Creator Hub) with a UIListLayout inside (UIListLayout | Documentation - Roblox Creator Hub).
- You can have a frame representing a template for a transaction with TextLabels, ImageLabels maybe, and this frame should be invisible and not in the scrolling frame.
- You must then write a script getting the template, and when you receive the transactions from the server, you get each transaction one by one (in the order if your table is indexed 1,2,3…) and you fill a cloned template with the information. You then parent the cloned template to the scrolling frame, and it will automatically be added to the list of previous items. I think you may also want to calculate the CanvasSize to fit all the transaction frames, or you can use the property AutomaticCanvasSize.
Prerequisites:
This process requires familiarity with ScrollingFrames, UiListLayout, and DataStores.
Creating a Transaction History UI:
-
Data Storage: Choose a data store solution (e.g., OrderedDataStore, DataStore) to store timestamps for each transaction.
-
Track Transactions: As transactions occur, record their timestamps using
os.time()
.
local timeOfTransaction = os.time()
os.time() returns the current system time in seconds since a specific point in time (often referred to as a Unix epoch timestamp).
Store Timestamps: Save the timeOfTransaction
value in your chosen data store for the specific player.
Display Transactions: When populating your transaction history UI:
Retrieve a list of all transaction timestamps from the data store.
Sort the list in descending order (newest to oldest) using the timestamps. This ensures the list displays transactions in the order they happened.
Ok, but the main problem is in that: how to make the 1, 2, 3… datastore?
You can use a table structure but you need to be familiar with tables (Tables | Documentation - Hub Création Roblox). For each key (1,2,3) representing the index of transation, you can save whatever you want in it (even a table). Here is a fast example as how it can look like :
transactions = { -- You use these {} to represent tables
1 = {}, -- In the {}, place whatever information you need about the transaction. Be careful : only data, not objects, you can put strings (text), numbers (integer or decimal) or tables, but not workspace objects
2 = {}, -- This is the second transaction, you might want the same data structure as the first one
3 = {}, -- Etc, you get the point
... = {}
}
Once you have the transactions table, you can use the SetAsync() or UpdateAsync() methods to save the player’s data in the datastore (GlobalDataStore | Documentation - Hub Création Roblox).
You can get whenever you want the same table of transactions using the GetAsync() (GlobalDataStore | Documentation - Hub Création Roblox) on the same key. Yes you need a unique key for each player to save their transactions (I suggest usinng their UserId as a key).
I’m using the last step (you can edit player’s data when they’re not online, but I’d recommend to add an check of player’s online status). But Idk how can I use table (I don’t even learned how to use it in scripts) in scripting, so I don’t know how to make data to be like 1, 2, 3…
Well you can learn how to use tables here : Tables | Documentation - Hub Création Roblox.
Basically, you want to add items only at the end of the table (since your transactions would be added in numerical order). To achieve this, you can either use table.insert(transactions_table, transaction)
or also transactions_table[#transactions_table+1] = transaction
. This will add your new transaction to the table of transactions.