Hello, everyone! I have a problem where I want to make a random minigame for the players every round. I can already make the minigames, but there is one problem I’m having. I’m trying to make the minigame without using repetitive if statements.I used math.random() to generate a random number but writing:
if num == 1 then function() if num == 2 then function() if num == 3 then function()Is too repetitive. How would I go about making this in an efficient way? I’m sure that games with lots of minigames don’t use 100 if statements, so someone helping me would be appreciated!
P.S: I had some ideas like putting all the maps into a folder called “Minigames” and then putting scripts inside the maps that get enabled when their game is called. Instead of using if statements, I would loop through the maps folder and choose a random minigame. However, too many scripts is annoying to work with, so I’m trying to use functions all in one script. Once again, thank you!
Hey, I am pretty sure there are some good online tutorials you can follow. Just try not to copy and paste make sure you understand and learn the script before you use it.
You are watching: How to make a minigame in roblox
If You Have Multiple Maps Then You Can Do It Like This…First Create A Folder Named Map In Replicated Storage And Place All Your Maps In There.
2.Now Create A Script In ServerScriptService And You Can Write Something Like This
local MapsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Map")local Maps = MapsFolder:GetChildren()local ChooseMap = Maps
I tried searching, but none of them had a game with more than two minigames, so they just used if statements.
The thing about this script is that it’s just choosing a map. I can already choose a random map and clone it, I just don’t know how to have a function run if that certain map is chosen
RefinedDev (Refined) September 9, 2020, 11:37am #6
What Function You Want To Do?Like A Timer System Or Somthing?
dodle120 (muffins) September 9, 2020, 11:40am #7
LIke rules. For example, one game can be a murder mystery where one player is handed a gun and another game can be musical chairs. I just don’t know how to run the murder mystery script if the murder mystery map is chosen.
See more: How Many Carbs In A Biscuit S And Gravy, Grams Of Carbohydrates In Biscuits
I thought of enabling scripts that are children of the map, but I don’t want too many scripts
RefinedDev (Refined) September 9, 2020, 12:27pm #9
You Can Make Module Scripts For Your Functions Then Require Them When The Map You Want Is Chosen.
CowboySticky (Sticky) September 9, 2020, 12:16pm #10
Here you go, this could help you:
game.Players.PlayerAdded:Connect(function() local Result = math.random(1,3)local FinalNumber = 0FinalNumber = Resultif FinalNumber == 1 thenendif FinalNumber == 2 thenendif FinalNumber == 3 thenendend)
That’s another thought I had but I wasn’t sure of how I would do it. I can make the functions in the module script, but how would I call it in the server script if a certain map is chosen. For example:
local minigames = require(ModuleScript) Minigames<#maps>
You Can See Whether The Map Chosen Name Is The Name Of Your Map, If Yes Then Require.Likeif Clone.Name == “Map” thenrequire(Clone.ModuleScript)
So I understand what you’re saying, but wouldn’t this require a module script for each minigame? Would that be okay for the game or ruin the performance?Also, wouldn’t this bring up the problem of multiple if statements I had before?
No, It Won’t Harm The Game Because When The Round Is Over The Clone Will Be Destroyed Which Will Also Destroy The Module Script So. It Shouldn’t Lag The Game.