How to make a saved global variable?

Hello,

I’m making a game where you search the User’s ID in the game and information about the user pops up. I have no issue doing this, but I want to implement another feature; How many times an ID has been searched up. An example of this is like the one in Outfit Checker:
image_2023-02-28_195720105
Any help on achieving this will be appreciated!

1 Like

I’m thinking you would need a datastore 1st off.
Then when a ID is serched you could add that to a running total for that ID to the datastore.
However this may get a bit out of control when 1000’s of players … Myself, I’d fake it or forget it.

I could be off here … never tied anything like this. Maybe someone else knows better.

But that does not save across servers; I want it to save to the server, not the player…
I tried using Messaging Service but that did not work…

DataStores don’t have to be specifically for players - they take a Key and a Value. In this case, your Key could be the ID of the user, and the Value could be the number of times they have been searched. Every time the user is searched, increment the Value in the DataStore by 1. Then, when an ID is searched, grab the value stored in the DataStore and display it. It should be quite a simple concept.

I would recommend using ProfileService or DataStore2 as accessing/potentially amending DataStores across multiple servers at the same time could lead to data loss.

A better solution for many requests happening all the time could potentially be a web server/external database, though this would require additional setup and cost.


Useful links:

Data Stores | Roblox Creator Documentation

1 Like

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