How to make a game with different maps for each round

Hello everyone, I am Jdubygamer. I am currently making a game called “Carbine Legends”. It is similar to Phantom Forces but also completely different. And as I am new to scripting and am still learning the basics, how would I want to go about making my game played on a different map for each round?

Would I have to do something with spawn points, teleportation, or anything else? I just have no idea and am trying to save some Robux here by scripting this type of stuff by myself.

Thanks!
— Jdubygamer.

Depends on what you’re looking for.

Map voting is a bit more complex, but there are tutorials on YouTube you can use to get started if that’s what you’re looking for. Perhaps this tutorial may be of assistance.

If you’re thinking of taking an easier route, you can utilize math.random

Place all of your maps in ServerStorage, perhaps in a folder titled ‘Maps’, and use math.random to have the game pick a random map out of the batch. Clone the chosen map and parent it to workspace, and there you go.

What I stated was the bare minimum basics, but you can build and expand the complexity from there.

Furthermore, you can use attributes or configurations inside the map models that store information such as Vector3 values that can be used for spawn points.

3 Likes

Alright. Would I have to assign maps variable numbers to do math.random? I am thinking of trying to do a map voting system.

If you’re looking to do a map voting system, it would be more complex. The tutorial I’ve sent you would be a great place to start.

As for math.random, if it’s a map voting system, you could still use it to create the lineup of maps in the vote queue for the round.

a basic method of finding a random map in your map folder could be done like:

local maps = game.ServerStorage.Maps:GetChildren()

local map = maps[math.random(1, #maps)]

Furthermore, you could utilize tables to remove a map from the potential choices once it’s picked for voting to prevent duplicates.

2 Likes

So would the #maps be the number of maps that I want to be included in the randomization? I might keep it as a random map when I release the game.

And how would I let it know when to change the map and where to spawn people? Would I just put that in the script or is that just the map randomization, not including where to spawn and when to randomize the map?

The code I provided above will automatically account for every map you have in the map folder. The “#maps” means the amount of children (in this case, maps), the “Map” folder contains.

maps[math.random(1, #maps)] means you’re randomly choosing one map out of the number of maps in the folder.

When changing the map, you would simply set remove the current map from workspace:

map:Destroy()

and then repeat the process.

As for spawning, refer to my prior post. You can put Vector3 values inside configurations or attributes in the map model, which can then be accessed by the script to understand where to spawn players.

1 Like

Here you go:
MapGenerator.rbxl (27.4 KB)
I hope this is what you wanted.

1 Like

Thanks! Would i be allowed to use this in a game??Or no cuz it might be considered a free model?

You can use it however you want.

1 Like

Alright. Thank you so much for your help! I haven’t gotten to the vector3 tutorial of AB’s scripting lessons, so once I learn that that should help me understand more.

Thank you! Will do! I will look into this!