Hey, it's the last section of the script... It moves the mini game from lighting as it should, but when it comes to removing it the script wont execute that part for some reason. It's in a loop so it should be checking it continuously and the global var (gameFinished) is being called correctly from the mini game script to give notification that it is complete.
Any ideas? Thanks in advance, Cuv.
disasters = {"Pitfall"}
countdownTime = 40
disasterTime = 1
_G.completed = 0
countdownMessage = "The next disaster will occur in %s seconds."
disasterMessage = "Survive: %s"
items = {}
leaderboard = game.Workspace:findFirstChild("BTS Leaderboard")
local w = game.Workspace:getChildren()
for i=1,#w do
if w[i].Name == "leaderboard" and w[i]:findFirstChild("running") ~= nil and w[i]:findFirstChild("coins") ~= nil then
leaderboard = w[i]
end
wait(0.2)
end
for i=1,#disasters do
local item = game.Lighting:findFirstChild(disasters[i])
if item ~= nil then
item.Parent = nil
table.insert(items, item)
else
print("Error! ", disasters[i], " was not found!")
end
wait(0.2)
end
function chooseDisaster()
return items[math.random(#items)]
end
function sethint(text)
local hint = game.Workspace:findFirstChild("hint")
if (hint ~= nil) then
hint.Text = text
else
print("Hint does not exist, creating...")
h = Instance.new("Hint")
h.Name = "hint"
h.Text = text
h.Parent = game.Workspace
end
end
function removeHint()
hint = game.Workspace:findFirstChild("hint")
if (hint ~= nil) then hint:remove() end
end
function countdown(time)
while (time > 0) do
if _G.completed == 0 then
wait(1)
time = time - 1
_G.countdowngo = ("Game starting in: "..time)
end
wait(0.1)
end
removeHint()
return true
end
while true do
countdown(countdownTime)
_G.countdowngo=countdownTime
if leaderboard ~= nil and leaderboard:findFirstChild("running") and leaderboard:findFirstChild("coins") then
leaderboard.coins.Value = 5
leaderboard.running.Value = true
end
local m = chooseDisaster():clone()
if disasterMessage ~= nil then
_G.countdowngo = ("Game: ".. m.Name)
wait(2)
end
m.Parent = game.Workspace
_G.completed = 1
m:makeJoints()
if _G.gameFinished == 1 then
m:remove()
wait(0.2)
_G.countdowngo = ("FINISHED")
end
if leaderboard ~= nil then
leaderboard.running.Value = false
end
wait(0.2)
end

2 comments
It doesn't do what you think it does. It's not waiting for the game to finish at all.
Surely the end While loop is continuously running to check whether the gameFinished variable is true or not?