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

Problem with minigame?

Asked by 8 years ago

So the this minigame is suppose to work is if all candles are lit (clicked on) before the time runs out, the game will display a hint telling the players that all candles were lit, but if some candles were not lit the game would display a hint that the players had failed, this is sort of like the sketch for the final product so I am not adding anything to the script that will kill the players for failing/winning or anything that rewards players for winning quite yet. but when i run the game, everything goes well until the time runs out and it stops the script and doesn't tell the players if they won or lost, candles are in the map and the code for the candles are

local candle = script.Parent
local fire = candle.Part.Fire
local light = candle.Part.PointLight

local function OnClick()
    fire.Enabled = true
    light.Enabled = true
end

candle.ClickDetector.MouseClick:connect(OnClick)

The code for the minigame script itself =


minigames = game.Lighting.Minigames:GetChildren() candles = game.Lighting.Minigames.Map.Candles: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 for i = 10, 1, -1 do h.Text = "Time left: " .. i wait(1) end h.Text = "Time is up..." wait (1) if candles.Part.Fire.Enabled == true 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
0
That's not how you're supposed to use bold text. User#6546 35 — 8y
0
You need to iterate through all the candles, for example: for _,v in pairs (candles:GetChildren()) do if v.Fire.Enabled == false then print("A candle wasn't lit!") end end TheDeadlyPanther 2460 — 8y

1 answer

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

Using :GetChildren() returns an object table of something's children. So, you have to loop through the table in order to check.

minigames = game.Lighting.Minigames:GetChildren()
candles =  game.Lighting.Minigames.Map.Candles: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
        for i = 10, 1, -1 do
            h.Text = "Time left: " .. i
            wait(1)
        end
        h.Text = "Time is up..."
        wait (1)

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

        if lit 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
0
I tried out the script and It told the player it had won regardless of if it did or not, not sure how to fix?? iiPrince 0 — 8y
Ad

Answer this question