Why does this check not work?

I’m trying to make a system where every 2 seconds it finishes printing, if there is something printing.

The Issue is that the check whether or not printing > 0 doesn’t work, but if change it so that its:

while true do
	printing -= 1
	printed += 1
	printedShown = "Printed: "..tostring(printed)
	printingShown = "Printing: "..tostring(printing)
	wait(0.5)
end

It works.

I’ve spent 30 minutes trying to fix it, I’ve also tried searching online if anybody had the same problem but couldn’t find anything

Code:

local simulator = script.Parent
local clicker = simulator["Main Clicker"]
local printing = 0
local printed = 0
local printingShown = clicker.PrintingShown.SurfaceGui.TextLabel
local printedShown= clicker.PrintedShown.SurfaceGui.TextLabel
local isTouched = false

local clickAmount = 1

local function addPrint()
	if isTouched == false then
		isTouched = true
		
		local luckyNumber = math.random(1,500)
		if luckyNumber == 250 then
			clickAmount += 1
			simulator.Lucky.Playing = true
		end
		
		printing += clickAmount
		printingShown.Text = "Printing: "..tostring(printing)
		simulator.ClickSound.Playing = true
		
		wait(0.275)
		isTouched = false
	end
end

clicker.ClickPart.ClickDetector.MouseClick:Connect(addPrint)

while printing > 0 do
	printing -= 1
	printed += 1
	printedShown = "Printed: "..tostring(printed)
	printingShown = "Printing: "..tostring(printing)
	wait(0.5)
end

Better not break the loop, just delay it

local simulator = script.Parent
local clicker = simulator["Main Clicker"]
local printing = 0
local printed = 0
local printingShown = clicker.PrintingShown.SurfaceGui.TextLabel
local printedShown= clicker.PrintedShown.SurfaceGui.TextLabel
local isTouched = false

local clickAmount = 1

local function addPrint()
	if isTouched == false then
		isTouched = true

		local luckyNumber = math.random(1,500)
		if luckyNumber == 250 then
			clickAmount += 1
			simulator.Lucky.Playing = true
		end

		printing += clickAmount
		printingShown.Text = "Printing: "..tostring(printing)
		simulator.ClickSound.Playing = true

		wait(0.275)
		isTouched = false
	end
end

clicker.ClickPart.ClickDetector.MouseClick:Connect(addPrint)

while wait(0.5) do
	if printing <= 0 then			continue				end
	printing -= 1
	printed += 1
	printedShown = "Printed: "..tostring(printed)
	printingShown = "Printing: "..tostring(printing)
end

I tried out the second version and it seems to work even if printing == 0 and never stops

Not sure why but it works even if printing <= 0 and never stop even if printing is lower than 0

Sorry, put the final if backwards :disappointed_relieved:, I’ll change it, if it doesn’t work, what do you want to do?

The basic idea is the player can click a brick and start to print something, and every 2 seconds a printing object finishes printing and becomes a printed object

Checking on an empty board, the script works, but it doesn’t get placed on the textlabel, right? that’s because the variable changes to a number when it should be an object

local simulator = script.Parent
local clicker = simulator["Main Clicker"]
local printing = 0
local printed = 0
local printingShown = clicker.PrintingShown.SurfaceGui.TextLabel
local printedShown= clicker.PrintedShown.SurfaceGui.TextLabel
local isTouched = false

local clickAmount = 1

local function addPrint()
	if isTouched == false then
		isTouched = true

		local luckyNumber = math.random(1,500)
		if luckyNumber == 250 then
			clickAmount += 1
			simulator.Lucky.Playing = true
		end

		printing += clickAmount
		printingShown.Text = "Printing: "..tostring(printing)
		simulator.ClickSound.Playing = true

		wait(0.275)
		isTouched = false
	end
end

clicker.ClickPart.ClickDetector.MouseClick:Connect(addPrint)

while wait(0.5) do
	if printing <= 0 then			continue				end
	printing -= 1
	printed += 1
	printedShown.Text = "Printed: "..tostring(printed)
	printingShown.Text = "Printing: "..tostring(printing)
end

I think i forgot to put in the Text after the variable but now it works

but i’m still not sure why the while loop still runs even when the printing variable is lower than 0
Ekrānuzņēmums 2021-07-05 210411