BearCode - Dynamic Twitter codes

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 :slight_smile:

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 :smiley:

72 Likes

No replies? Anyways, I’d just like to let you know this sounds fantastic and I will definitely use it! :smile:

7 Likes

Literally an amazing release, can’t believe no one has replied!

4 Likes

Pretty sweet, dude. I really like the feature where codes can be used x amount of times. I’d love to see a feature where codes can be created by Developers in-game without having to go into Studio - as you mentioned! :^)

3 Likes

Clean, smooth, very easy to setup. This is really amazing brother, I can see this going very far. You should for sure keep this updated, everyone loves it.

4 Likes

How do I reference the player who redeemed the code in the reward functions module?

4 Likes

You know, that may have been a good thing for me to have done in hindsight!

Looks like I forgot, nether the less should be an easy fix if you can’t wait till I get round to it tomorrow. If you access the main module and find the line of code which calls the function (search ‘RewardFunction’ to find it faster) and just pass the player argument in the brackets.

Thanks for letting me know, this was really an oversight on my part

3 Likes

I’ve been working for a bit since I just got home from being up North, and I can say this system is very easy (at least from my standpoint) to take and modify for intermediate Developers. I’ve already made two changes:

A) custom popup messages when the player redeems a code
B) players can now be referenced in bound reward functions

I also made my own UI, here’s a video showcasing the features as well as the UI.

(quality isn’t the best, sorry!)

5 Likes

I have a problem, 16:25:48.604 - DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 167425533. This error pops up when I am using the datastore, how can I fix it?

1 Like

My code alone shouldn’t be overloading the datastores, you may have your own external datastore code filling up the queue and mine is pushing it over the limit.

If this is not the case I’d reccomend upping the denounce for code copies refreshing.

2 Likes

Well my game runs on Datastore2, and I couldnt figure out a way to convert your code over to Datastore 2 so I think thats the error there

1 Like

(May be forgetting how I wrote the code)

But my code system uses one get request and one set request per player and only gets and sets the data if the player has used the code system in that play session, copies data are by default refreshed every (60 seconds + time before next code entry).

Knowing roblox’s datastore limits I can’t really see how this would exceed them, however as I say try uppping the denounces in the settings and see how that goes.

Edit:
Thinking of it though, if you are overloading the a code which has copies that may start to exceed your set requests, you could write custom logic to save at intervals but you would lose a lot of accuracy here.

2 Likes

Well I have upped the debouncetime to 10 and the error still occurs, is there a limit to this?

1 Like

I can’t really help you without your external code / how your using the system in that play session, sorry.

From testing and other’s experience I havn’t heard reports of the system exceeding the limit and I am struggling to grasp how it would with correct usage.

If you want me to take a look at it later feel free to DM me a repro

3 Likes

Sure I’ll DM you. Thanks for helping me out

2 Likes

Looks great! I tried this out and I definitely recommend it. Works flawlessly for me. <3

2 Likes

I am having the same issue with the DataStore. (An empty experience with only your module and the DataStore2 module)

A copy of the place: CodeBearCopy.rbxl (173.4 KB)

Sorry for the bump, but would this support having the codes table on an external site such as Pastebin to allow for servers to release instantly on old servers?

1 Like

agreed, not only that im struggling with passing the player to the reward function.
I know its been 2 years but a update would be nice!

1 Like

This is awesome! I will most likely be using this!

1 Like