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

What is wrong with my King of the Hill script?

Asked by 9 years ago

I believe the error is at line 6, where it defines the hint's text. The hint's text shows up, but the timer blue and red variables don't go down (they may, but the text on the hint does not change.)

local h = Instance.new("Hint", game.Workspace)
TimerBlue = 360
TimerRed = 360
TimerTie = 360

while true do
    h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
    wait(1)
end

    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright blue") do
            wait(1)
            TimerBlue = TimerBlue - 1
            if TimerBlue == 0 then break end
    end

    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright red") do
            wait(1)
            TimerRed = TimerRed - 1
            if TimerRed == 0 then break end
    end

if TimerBlue == 0 and game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright blue") then
    game.Workspace.VictoryDefeat.Value = true
end

if TimerRed == 0 and game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright red") then
    game.Workspace.VictoryDefeat.Value = false
    game.Workspace.Red.Value = true
end
0
Your while loop is an infinite loop so anything below it will not run. NotsoPenguin 705 — 9y
0
Above is right. I'll answer it more clearly. DevChris 235 — 9y

2 answers

Log in to vote
2
Answered by
DevChris 235 Moderation Voter
9 years ago

Where you put

while true do
    h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
    wait(1)
end

This is a while loop, and keeps running until the condition (true) is false. Since true is true and you can't change it (and it's not a variable either), it won't stop running to go on to the next while. Now since I know you don't want to stop it, put a coroutine around it to "hide" it.

coroutine.wrap(function()
    while true do
        h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
        wait(1)
    end
end)()
0
Thank you! Will try out! I'm still learning the lua programming language Noobegai -4 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

It still does the same thing: no error, here is my new script:

local h = Instance.new("Hint", game.Workspace)
TimerBlue = 360
TimerRed = 360
coroutine.wrap(function()
        while true do
            h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
            wait(1)
        end
end)()

coroutine.wrap(function()
    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright blue") do
        wait(1)
        TimerBlue = TimerBlue - 1
        if TimerBlue == 0 then break end
    end
end)

coroutine.wrap(function()
    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright red") do
        wait(1)
        TimerRed = TimerRed - 1
        if TimerRed == 0 then break end
    end
end)
0
nvm it works now! I just smooshed everything into one coroutine function Noobegai -4 — 9y

Answer this question