Cant break while loop

Hi i have this script, that make a random number appear in the gui, but i dont know how to break the loop, i tried defining a variable named Running and using an

While running do 

But i still wont work, any help?

Also here is the full script

local gui = script.Parent
local text = gui.TextLabel
local running = true
print(running)
while running do
	wait()
	text.Text = math.random(1, 5)
end
running = false
print(running)

image

Well this is because the loop stops the code from “running”. You can either use a task.spawn function or coroutines to run the code afterwards

task.spawn(function()
	while running do
		wait()
		text.Text = math.random(1, 5)
	end
end)

But why do you need a loop when you set the boolean to false right afterwards?

1 Like

Thank you!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.