I’m trying to get a Halloween game pushed out by October 01, 2021.
In the Halloween game, I’m attempting to make a system where you click a door, you receive a random amount of candy ranging from 1-10. Upon receiving the candy when clicked, there is a cooldown of 135 seconds. (2 minutes, 15 seconds).
Anyone who successfully helps me will receive special perks upon the games release, and even sneak peeks via DevForum messages.
Those who give a decent attempt will also receive smaller perks. |
Thank you so much in advance, and a very-very-very-early happy halloween.
I’d like to help you, however first I would like to ask, will the cooldowns be global (once one person uses the door, its unusable) or will it be separate for everyone (cooldowns are local to the player).
There are several ways you could go about this, some more efficient than others, but all ultimately serving the same purpose. I’ll, however, walk you through, step by step, how you’d make a candy system.
Step 1 - You’ll need to get all of your doors set up in a system. This can be done by providing each player in the game a table, which has all doors in the game. This would look something like this: player = {DOORA = 0, DOORB = 0, DOORC = 0, DOORD = 0}, you get the idea. This can be done in a separate module.
Step 2 - Next, you’ll need to make values for the amount of candy they’ve recieved. This can be done in the table made previously, meaning it’ll now look like playerTable = {<DOOR_DATA>, Candy = 0}.
Step 3 - Third, whenever a player knocks on a door, through whichever means you choose to use, the server will pick a random number between 1 and 10 with math.random(1,10). This will then be added onto the candy value, and the doors value in the player table will be stored as the tick (current time). This may sound confusing, but this’ll save us time and resources instead of running several threads.
The reason we save it as tick is so that we can check if its on cooldown by doing current_time - old_time. If this is bigger than 135s, it’ll be off cooldown. If not, it’ll still be on cooldown and unusable. This will save us resources as otherwise we’d have to do alot of threading, functions and irrelevant work.
I cannot give you a full script (forum rules) so I’ll explain instead.
When a player joins create a Cooldown value within their Player. Have this value count down by 1 every second (via wait(1)) as long as the value is bigger than 0.
When the door is clicked, you can use math.random(1, 10) combined in order to give a random number of candy.
When the door has been opened you should check if the player’s cooldown value is equal to 0, if so increase their candy and set their cooldown to 135.