A round system for a projectiles game

Hello developers,
Getting straight the point, I started working on a new project, it consists of randomly choosing a player from 15 players every round, and giving them a certain item, and they must hit a target under 45 seconds (a dart to hit the bullseye, a football to score a goal…), if they do that, they will get a prize, if they don’t, the prize scales up and another player will be chosen to do the same thing. If all players fail, they will just get nothing.

My question is, how can I do that? At first, I thought of using dictionaries and module scripts, to store the players’ stats like hasWon and hasBeenChosen etc… and then loop through a minigames folder which has module scripts in it and call the function inside of a randomly chosen one, and also giving them a randomly chosen player.

Any help is appreciated!

Hello? Any help?

spoiler alert

Hi, i’d use module scripts like you’ve mentioned. To detect when a minigame should end (and a new one begin consequently) you can use a BindableEvent.

Writing this while i’m not home so pardon me if there’s errors:

local bindable = game.ServerStorage.RoundEnded; -- you can use whatever name you'd like for the bindable or even make it directly from the script

bindable.Event:Connect(function()
   local mgames = game.ServerStorage.MinigameModules:GetChildren(); -- gets all the minigame modules under a folder "MinigameModules"
   local module = mgames[math.random(1, #mgames)]:Clone(); -- retrieve a random module from the folder
   local totPlrs = math.clamp(#game.Players:GetPlayers(), 1, 15); -- math.clamp makes sure the code doesn't break if there's less/more than 15 players
   local plr = game.Players:GetPlayers()[math.random(1, totPlrs)]; -- retrieve a random player
   local required = require(module);
   required:Execute(plr); -- you might use a different way to execute the module script, this is how i'd do it
end);

Of course in the modules you’d do all the checks that make sure a player has completed the minigame, the time has ran out, etc. and fire the bindable to communicate to the handler script the minigame ended.

This is how i’d do it personally. You may prefer another way, also based on how you want your game to work, but this should do the trick for you. To automatically commence a new minigame when a player joins, you can use a simple task.wait and fire the bindable.

1 Like

Thanks man, this is a really logical way to do it. Will try it asap when i get home as well. :+1:

Here is another method you can use utilizing Promises to organize your code structure:

1 Like