Live Redeemable Codes

Hi there. I hope your having a great day so far. I’m currently developing a game and would like to know how I would create a live code system that doesn’t require me to shut down servers. What would be the easiest way to do so?

2 Likes

Theoretical Method:

You could update codes by uploading a module to the website with codes inside and the corresponding award.

Updating the module is as simple as overwriting the existing module with new codes and the corresponding award, but you would need to require the module repeatedly.

Other Methods:

You could make use of messaging service to inform other servers that there’s a new code added. You just need to join a server and perhaps create an interface for you to broadcast the code.

Another way would be Data Stores by again creating an interface that can add codes so that a server script can listen for new codes or repeatedly check for new ones.

An extreme method would be to host your own data base server that can hold codes and communicate with roblox servers. This method would require additional knowledge to achieve.

This last method was something I just thought about, but you could create a script to go through your twitter or whatever social media via HttpService and scan for codes using their API, i haven’t tried this before, but it seems possible.

3 Likes

seems interesting. Is there any way that google spreadsheet can work with the live codes?

I am not familiar with using google spreadsheets as a database because it has been mentioned many times that “Google Spreadsheets are not databases” and google has limits depending on your account type and implementation. But yes, google spreadsheets can be used as a database for codes.

1 Like

Requiring a module repeatedly does not reload / run it again. A module will only load & run the first time it’s required. Following requires return the value returned upon first evaluation.
Try using data stores or some online charts x httpservice instead, Taik.

1 Like

Once a module is required from the web, the initial version prior to requiring is cached?

Modules cache; if you require a module, requiring it again won’t update it.

so yes, the initial version is cached. If you make a module that says

local module = {"hi"}

return module

then update it to say (while the game is running)

local module = {"hi", "hello", "greetings"}

return module

then the module won’t update until it’s in a server it hasn’t been required in before. Caching can be annoying, I had to deal with it in a community script builder.

3 Likes

You can use Gist or pastebin (I recommend gist since you can make json files)

1 Like

Couldnt you use loadAsset, then require it?

Pretty sure LoadAsset caches as well.

Ah, figured it probably would. In that case I would use a raw pastebin link and use https service to get it and decode it.

ive tried using pastebin. Everything works fine until i try to redeem which will then look through the module script which holds all the code. I cant get the code to work on a module script since it would just print out code invalid if i try to redeem it.

Personally what I would do is have a DataStore
And inside of that DataStore I would have a table, and inside that table is the code itself and the time values, for example:

local Codes = {
    ["Code1"] = {"ExampleCode", StartTime, EndTime}
}

And what I would do with the DataStore is have a admin command setup where I can go into the game and simply add keys that way and save them to the table. Then in addition to this I would use Roblox’s time functions: os.time and os.date

Sorry I didn’t go into more detail but this was just how I would go about doing it.
Goodluck!

2 Likes

Could just use http service to fetch a model’s description.

I use Pastebin for my codes and have had no issues. It’s my method of preference because you can publish and remove codes almost instantly. It also isn’t terribly hard once you get it set up as well. You should check out the replies on my post as they helped me tons.

1 Like

Dont store the code in pastebin; store the codes array. When you want to change them,JSON Encode it, then change the pastebin to that. Then, getAsync the RAW (just text) pastebin. Once you do, JSON Decode that, and you have the array.

local data = game:GetService("HttpsService"):GetAsync(pastebinlink/raw
local codesArray = game:GetService("HttpsService"):JSONDecode(data)

Store your codes in a array. Loop over it to see if the code matches any parts.

Alright so I decided to work out this problem without using an external services

--Disclaimer the dates are in UTC time

local Codes = {
	["Code1"] = {
		["StartingInformation"] = {
			["year"] = 2019; --Year the code will start in
			["month"] = 5; --Month the code will start in
			["yday"] = 124; --Day of the year the code will start on
		};
		["EndingInformation"] = {
			["year"] = 2019; --Year the code will end in
			["month"] = 5; --Month the code will end in
			["yday"] = 125; --Day of the year the code will end on
		};
	};
}

function OnCode(Player, Code) --Pretend this is the function that filters codes from players
	--Check to see if the code is valid
	if Codes[Code] then
		--I will just be coding the time functions
		local Date = os.date("!*t")
		--First we will make sure the year is valid
		if Date["year"] >= Codes["Code1"]["StartingInformation"]["year"] and Date["year"] <= Codes["Code1"]["StartingInformation"]["year"] then
			--The year is valid!
			--Now we will validate the month
			if Date["month"] >= Codes["Code1"]["StartingInformation"]["month"] and Date["month"] <= Codes["Code1"]["StartingInformation"]["month"] then
				--The month is valid!
				--We will now validate the day!
				if Date["yday"] >= Codes["Code1"]["StartingInformation"]["yday"] and Date["yday"] <= Codes["Code1"]["StartingInformation"]["yday"] then
					--The date is also valid!
					--You know know the code is valid!
				end
			end
		end
	end
end

You can add more details time dates if you want, you can find more detailed time variables here

1 Like

You see though, here’s the thing; these aren’t necessarily the kind of live that OP wants to achieve. You will still have to hard code in codes and what kind of reward they should assign. This therefore doesn’t make this any different than updating your game with a code for use in new servers and removing it when the time period is over.

What OP wants to be able to do is register and remove codes for use in-game without updating the actual game and shutting down all servers or wait for old servers to phase out for such changes to take effect.

You don’t need to remove it when it’s over, it auto detects the time and the code won’t work after the time expires.

I don’t think you quite understand what I meant. You still have to manually add and remove codes to the system, which doesn’t make this any better than simply adding a code to your game and shutting down.

The most your code does is reject a code if it’s not entered within a specified time frame via os.date(). It doesn’t achieve the use case OP is looking for, which is to add/remove codes without hard coding them or shutting down the game. This still requires a shut down or server phase out - the Codes table is hard coded into the script.

Please go over my response again.