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.)

01local h = Instance.new("Hint", game.Workspace)
02TimerBlue = 360
03TimerRed = 360
04TimerTie = 360
05 
06while true do
07    h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
08    wait(1)
09end
10 
11    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright blue") do
12            wait(1)
13            TimerBlue = TimerBlue - 1
14            if TimerBlue == 0 then break end
15    end
View all 30 lines...
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

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

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.

1coroutine.wrap(function()
2    while true do
3        h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
4        wait(1)
5    end
6end)()
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:

01local h = Instance.new("Hint", game.Workspace)
02TimerBlue = 360
03TimerRed = 360
04coroutine.wrap(function()
05        while true do
06            h.Text = "Blue Timer: " ..TimerBlue .." | " .."Red Timer: " ..TimerRed
07            wait(1)
08        end
09end)()
10 
11coroutine.wrap(function()
12    while game.Workspace.AbandonedSkyMill.Point.Light.BrickColor == BrickColor.new("Bright blue") do
13        wait(1)
14        TimerBlue = TimerBlue - 1
15        if TimerBlue == 0 then break end
View all 25 lines...
0
nvm it works now! I just smooshed everything into one coroutine function Noobegai -4 — 9y

Answer this question