Randomly Selected Course

Submitted by ian on Sun, 03/17/2019 - 13:48
Picture of the game
The game with the courses loaded. The red parts are placeholders that will get replaced later on.

Recently, I started working on a game. The objective of the game is to go as far as you can, while not falling into the water. The stages in the game are changed randomly every 30 seconds.

Making the loading system was somewhat easy. In Roblox, each game has parents like game.Workspace, game.Lighting, etc. When models are in game.Lighting, you cannot interact with them, or see them while playing the game. To identify what stage was which, each stage was named 1A, 2B, 4C, etc. The number is what level it is, and the letter is what version of the level it should load (A-C). When loading all of the stages, it picks a random letter for each level. Then, it changes all of the levels parents to game.Workspace, allowing the player to interact with it.

The system to load stages is similar to this. Instead of giving each stage a random letter (A-C) and all, it checks what levels are loaded, and unloads them by changing the parent back to game.Lighting. Then the stages will load again.

 

The loading/unloading scripts are not that hard to make. In fact, its only like 3 lines each. Here are the scripts:

Keep in mind that there is another script that calls the function and gets the stage.

LOAD:

function LoadStage(stage)
     game.Lighting[stage].Parent = game.Workspace
end

UNLOAD:

function UnloadStage(stage)
     game.Workspace[stage].Parent = game.Lighting
end