Issue with for loop iteration returning nil

So I’m working on a promotional code system that iterates through Trello cards, but for some reason whenever it iterates, it looks for the first code only and returns all other codes as nil.

Here’s what it looks like:

for i,v in next,Codes do
	if text == v.name then
		if CodesUsed:FindFirstChild(text) then
			result = "CODE ALREADY USED"
		elseif v.dueComplete == true then
			result = "CODE EXPIRED"
		else
		local used = Instance.new("BoolValue",CodesUsed)
		used.Name = text
		used.Value = true
		Credits.Value = Credits.Value + v.desc
		result = "SUCCESS! "..v.desc.." COINS REWARDED"
		end
	else
		result = "Invalid Code"
	end
end
	return result 
end

I’m pretty sure it basically hit a roadblock whenever the inputted code ~= the name of the first iterated promo code and returns “Invalid Code”, instead of checking through all of the promo codes.

Any ideas on how to overcome this?

Found a simpler way to return the result, just make the result variable “Invalid Code” and completely remove the else.

local result = "Invalid Code"
for i,v in next,Codes do
	if text == v.name then
		if CodesUsed:FindFirstChild(text) then
			result = "CODE ALREADY USED"
		elseif v.due < dateValue then
			result = "CODE EXPIRED"
		else
		local used = Instance.new("BoolValue",CodesUsed)
		used.Name = text
		used.Value = true
		Credits.Value = Credits.Value + v.desc
		result = "SUCCESS! "..v.desc.." COINS REWARDED"
		end
	end
end
	return result 
end

If there’s another way to do this please let me know.