Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with minigame?

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

2 comments

0

That's not how you're supposed to use bold text.

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

1 answer

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

1 comment

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??

This discussion is preserved as it was. New answers, comments, and votes are closed.