Problem with thousands of prints at once

i’ve been trying to write a countdown script for a game, using values to signal when to do certain lines, problem is in the second if statement i’ve tried debounce, i’ve tried wait, and i’m still getting hundreds and even thousands of prints that almost crash my studio, i seriously need some advice with this, since i think it may be the if statement, but not sure, all i want is the print to print once, not many times as said before

local servertime = game.ReplicatedStorage:FindFirstChild("ServerTime")
local Evalue = game.ReplicatedStorage:FindFirstChild("Evalue")
local folder = game.ReplicatedStorage.enemies


while true do
	if Evalue.Value == 0 then
		for i = 10, 0, -1 do
			servertime.Value = i
			task.wait(1)
			if i == 0 then
				Evalue.Value = 1
			end
		end
	end
	
	if Evalue.Value == 1 then 
		local parts = {}
		for i, v in pairs(folder:GetChildren()) do
			table.insert(parts, v)
		end
		local part = math.random(1,5)
		print(part) -- here, is the line that repeats for some reason
	end
    
	if Evalue.Value == 3 then
		for i = 20, 0, -1 do
			servertime.Value = i
			task.wait(1)
			if i == 0 then
				Evalue.Value = 0
			end
		end
	end
end

i also though it may be the math.random but i’m pretty sure it’s only supposed to pick one, but i don’t know, any help?

When your Evalue’s Value is 1, it will run your second condition, and that code block doesn’t have any waits on it. Based on your pattern, did you mean to change Evalue to 3? If so, you don’t need that Evalue object, but just stack the processes one after another.

evalue 3 is changed in a different script, i use those to signal a different script to do other tasks, also, where do i put the wait?

I would recommend using bindables instead. With a BindableEvent, you can listen to it in another script to perform some other task by firing that BindableEvent. BindableFunctions will do the same thing except it calls a binded function instead, and will wait for a response back.

As for your issue, add a wait after your print to prevent crashing.

yeah, that works pretty much, i forgot to specify i only want it to print once, sorry for not specifying before

That is where event based code comes in handy. Otherwise, you can always do

repeat task.wait() until Evalue.Value ~= 2

after your print.