About
Looking around the forum, recently I noticed there were no dynamic solutions for developers to easily add both simple and complex codes to their game, a problem I was keen to solve, and since I wished to rewrite blox royale’s twitter code system.
Gif of the code system in action!
Features
Multiple, easy to customise settings including:
Case sensitive [Boolean]
Ignoring if the code is empty / nil [Boolean]
Showing the expiration date if expired [Boolean]
Debounce time [Int]
Copies Datastore refresh time [Int]
The ability to set custom responses for 7 different error types to provide excellent UX.
Code being Valid
Code not existing
Code already redeemed
Code expired
Code sold out
Code entry being spammed
No code being entered
It also provides settings to change the colour of the responses:
Negative response colour
Positive response colour
Specific code settings:
One thing I really wanted to achieve with this module was keeping it both dynamic and simple and easy to use, therefor you are able to add codes by only modifying three settings while providing an infinite amount of possibilities:
Expiration - Time in seconds after unix epoch that the code expires (If you do not want the code to expire set this to nil)
Copies - The amount of players who can redeem your code, if you don’t want the copies to run out then set to nil (You can also use a big number but the module is optimised to not check the copies if the code has unlimited copies)
RewardFunction - This is the function which runs when the code is successfully redeemed
How to use
Go into the ‘ActiveCodes’ Module and you will see this with three example codes:
local ActiveCodes = {
['UrsaIsTheBest'] = {ExpirationDate = nil, Copies = 10, RewardFunction = RewardFunctions.Ursa},
['1CopyTest'] = {ExpirationDate = nil, Copies = 1, RewardFunction = RewardFunctions.Ursa},
['ExpiredCodeTest'] = {ExpirationDate = 10, Copies = nil, RewardFunction = RewardFunctions.Ursa}
}
To add a new code, copy the last line of code onto a new line, Then edit the Index to what you want the code to be. Then set the expiration date to the time after unix epoch which you want the code to expire on, set the copies to how many copies of the code you wish to exist, and set the reward function. I have provided a module called reward functions for these to be stored, however any valid function will work
How do I get this?
If you would consider yourself a decent programmer and you understand most the tutorial I would recommend the module model link here.
If you are not that good a programmer and you struggled to follow this tutorial here is a place file with example UI and scripts provided:
BearCodeExample.rbxl (33.3 KB)
Do I plan to update this?
I don’t really have any direct plans to update this, im considering adding a method to add codes to live games without the need to update them, however this presents a multitude of problems given you cannot save functions in datastore and I can’t rely on everyone having http service enabled.
Find a bug?
I admit I didn’t vigorously test this and it is likely there will be ways to break it, if you do find a bug let me know and ill patch it when I get round to it, As a side note in relation to copies, This module does not use messaging service to maintain accurate records of copies and instead fetches the amount of copies when it is needed (Whenever the code is used with a 60 second deboucen by default) Therefor this should not be used if you wish to only distribute a perfectly precise amount of copies (<100). You can refine this by decreasing the debounce in the settings module but I would be wary of datastore limits.
Too complex?
While I tried to make this module as simple as possible I understand parts of it (Including the custom functions) part may be complex to some hence why I am marketing this at intermediate level developers, if you wish to use a simpler system I would recommend @wravager’s system which is a lot easier to understand however less dynamic and customisable.
Credits to @LuaBearyGood appreciated