Help with counter not adding

My problem is with this code:

local Luck = 26

local function GetLowestPossibleMoney()
	local Counter = 0
	for _, Money in pairs(Moneys) do
		Counter += 1
		local ChanceFor = Money.Chance / Luck
		
		if ChanceFor >= 1 then
			return  Money.Name
		elseif Counter == #Money  then
			 return Money.Name
		end
	end
end

print(GetLowestPossibleMoney())

That the counter isnt adding up and making it not print anything can someone tell me what im doing wrong?

Every time you will fire the event “counter” will set to 0

1 Like

So should i make the counter in the loop?

Put it after you set the luck variable

1 Like

It will only change in the function right?

The “Counter” variable is inside the function that you later on call in your script. So every time the function activates, the variable’s value resets to 0. Put the variable outside the function and that shouldn’t be a problem.

(I have almost no scripting knowledge so all I can say is this lol.)

1 Like

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