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

What is wrong with my King of the Hill script?

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

2 comments

0

Your while loop is an infinite loop so anything below it will not run.

0

Above is right. I'll answer it more clearly.

2 answers

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

1 comment

0

Thank you! Will try out! I'm still learning the lua programming language

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)

1 comment

0

nvm it works now! I just smooshed everything into one coroutine function

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