Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Minigame script problem?

Asked by 8 years ago

So the minigame requires you to light (click) all the candles in the loaded map, but for some reason end result is always false, and tells the player he lost regardless if the candles are lit or not, I will also provide the structure of the candle if it helps.

game.Lighting.Minigames.Candles.Candle.Part.Fire
minigames = game.Lighting.Minigames:GetChildren()
h = Instance.new("Hint",game.Workspace)
while true do
    if game.Players.NumPlayers > 0 then
        h.Text = "Picking random map..."
        wait(3)
        ranGame = math.random (1, #minigames)
        gameChosen = minigames[ranGame]
        h.Text = "Minigames Chosen:" .. gameChosen.Name
        wait(3)
        gameChosenClone = gameChosen:Clone()
        gameChosenClone.Parent = game.Workspace


wait(2)
end

plrs = game.Players:GetChildren()
    for i = 1, #plrs do
            plrs[i].Character:MoveTo(gameChosen.Spawn.Position)
        for i = 15, 1, -1 do
            h.Text = "Time left: " .. i
            wait(1)
        end
        h.Text = "Time is up..."
        wait (1)

        candles  = gameChosen.Candles:GetChildren()


        for _, v in pairs(candles) do -- Loop through the children
            if v.Part.Fire.Enabled == true then
                islit = true
                else islit = false
                break
            end
        end

        if islit then
            h.Text = "All the candles have been lit!, the Demon has decided not to come!"
        else 
            h.Text = "Not all of the candles were lit!, you have failed"
        end
        wait(3)
        gameChosenClone:Destroy()
    end
    wait(1)
end

1 answer

Log in to vote
0
Answered by 8 years ago

As far as I can see, you do not specify islit outside of the forloop, so it only sets an instance of islit locally. So when you check islit at line 39, you are checking a definitely false variable (variables that do not exist are nil -- I.E. false)


plrs = game.Players:GetChildren() for i = 1, #plrs do plrs[i].Character:MoveTo(gameChosen.Spawn.Position) for i = 15, 1, -1 do h.Text = "Time left: " .. i wait(1) end h.Text = "Time is up..." wait (1) candles = gameChosen.Candles:GetChildren() islit = false for _, v in pairs(candles) do -- Loop through the children if v.Part.Fire.Enabled == true then islit = true else islit = false break end end if islit then h.Text = "All the candles have been lit!, the Demon has decided not to come!" else h.Text = "Not all of the candles were lit!, you have failed" end wait(3) gameChosenClone:Destroy() end wait(1) end

I believe - but do not hold me to it - that this should work.

Ad

Answer this question