How to keep a roblox script going even if it stops on an If Statement

Hay developers, I am trying to make a script that loads 3 random obbys based on a math.random(1,3)

The thing is once it reaches the first if statement that matches the random number. It stops the scripts and only loads that one obby. So im stuck with a 1 stage obby when im wanting 3 to be loaded at once. The script can be found bellow. Any help is awesome! Thank you!

local ST = game.Lighting.SelfTraining

local RanNum1 = math.random(1,3)

local RanNum2 = math.random(1,3)

local RanNum3 = math.random(1,3)

if RanNum1 == 1 then

ST.Platform1O1.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum1 == 2 then

ST.Platform1O2.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum1 == 3 then

ST.Platform1O3.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end


if RanNum2 == 1 then

ST.Platform2O1.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum2 == 2 then

ST.Platform2O2.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum2 == 3 then

ST.Platform2O3.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum3 == 1 then

ST.Platform3O1.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum3 == 2 then

ST.Platform3O2.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

if RanNum3 == 3 then

ST.Platform3O3.Parent = workspace

wait(60)

ST.Platform1O1.Parent = game.Lighting.SelfTraining

end

wouldn’t you want to clone the stages or whatever you want to be cloned?

It does not matter to me. But if that fixed the problem then sure I guess.

if you use the function, spawn() then you can spawn a function on a different thread, so for example you can wrap the if statement in a spawn(function().

Example:

local value=true
spawn(function() -- Spawn new thread
    if value then
       while true do
           wait() -- infinitely yielding example
       end
    end
end)
print("Done") -- The spawn(function() spawned a new thread so it runs seperate from the main thread.

You can use while true do. Correct me if i am wrong.