Writing a Code System

Howdy, developers! I’m trying to make my own code system but I have no idea where to begin.

I want players to be able to enter codes into a text box and receive special items. I also want for these codes to be changeable on the fly. For example, I would use a code during a stream and then immediately disable the code when the stream ends, perhaps using pastebin or something. I don’t want the codes to be pre-added to game updates because I’d like a little more control.

What would you do to accomplish this? What is required on the client’s end and the server’s end? Is there any required formatting for a pastebin file?

I appreciate all responses!

1 Like

Probably the easiest way of doing this is have a DataStore with codes that you can modify on the go, like with chat commands or a temporary script to push / pull data from it. Each server will then update their “codes cache” based on the data stored in that DataStore. Let’s say each few seconds, minute, etc. (Up to you)

The moment you change something in the DataStore, it’ll take the select amount of time to communicate across your entire game universe, allowing you to edit/add/remove them live.

This question has been answered here:
Simple Twitter Code System for Beginners

The example is for a dynamic system that does not rely on keeping the codes in data stores. The OP’s example uses a Roblox asset description, but some replies suggested pastebin.

1 Like

You could develop some sort of interface to allow you to add codes from live servers vs hard-coding them.

All you’d then have to provide is a code, a duration and the rewardData through the interface and everything else would be up to your implementation on the back-end.

i.e: `{"XYZ" = {duration = os.time() + 60*60*15; rewardData = {"Gold", 500}}`

from the client, permissions verification on the server, and everything else from there.

1 Like

I think this is good, but would google sheets work for something like this?

i.e if the code is in google sheets then continue,

what’s given to the player would be in the next block in sheets

i.e NAME REWARDTYPE REWARD

Twitch, Coins, 50

Currently trying to use pastebin. I did get it to load the codes using HttpService, however I don’t know what the limitations are. Would refreshing the code since every 60 seconds using HttpService cause failure in any way?

Not that I am aware. During my testing, changing the pastebin code resulted in HttpService seeing the update immediately. Seems that each HttpService call is independent. I think the thread I mentioned has some talk of possible caching, but I don’t remember the details.