Help With Script Not Reseting A Value When Another Item Is Added

Part of my code. (I haven’t coded in months and this is old code so I may just be dumb.)

local newRun = false
local i = 3

tradeFolder.updateLocked.OnClientEvent:Connect(function(value)
	print("lock stuff")
	if value then
		isLocked = false
	else
		if i ~= 3 then
			i = 3
		end
		isLocked = true

		acceptButton.BackgroundColor3 = Color3.fromRGB(28, 93, 24)
		declineButton.BackgroundColor3 = Color3.fromRGB(102, 15, 17)
		
		repeat
			warn("repeating")
			acceptButton.Text = tostring("ACCEPT " .. i)
			declineButton.Text = tostring("DECLINE " .. i)
			i -= 1
			wait(1)
		until i == 0

		isLocked = false
		acceptButton.Text = "ACCEPT"
		acceptButton.BackgroundColor3 = Color3.fromRGB(56, 182, 47)
		declineButton.Text = "DECLINE"
		declineButton.BackgroundColor3 = Color3.fromRGB(163, 25, 27)
	end
end)

Video of what is happening… (keep an eye on the buttons and the items being added)

Look, this countdown starts many times as it getting event fired, you need make a countdown separately from On Client Event, bcuz it works like a spawn(function() and this make too much “repeat” functions on this countdown timer.

What? I’m confused on what you mean.

Understandable, just make function that gonna do repeat once instead of:

		repeat
			warn("repeating")
			acceptButton.Text = tostring("ACCEPT " .. i)
			declineButton.Text = tostring("DECLINE " .. i)
			i -= 1
			wait(1)
		until i == 0