Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

For i = 60,0,-1 do loop stops at 1??

for i = 60, 0, -1 do
wait(1)
if i == 0 then
Cash.Value = Cash.Value + 100
for _,v in pairs(MinWage) do
if Rank.Value == v then
Cash.Value = Cash.Value + 100
i = 60
end
end
for _,v in pairs(MedWage) do
if Rank.Value == v then
Cash.Value = Cash.Value + 200
i = 60
end
end
for _,v in pairs(MaxWage) do
if Rank.Value == v then
Cash.Value = Cash.Value + 300
i = 60
end
end
for _,v in pairs(AdminWage) do
if Rank.Value == v then
Cash.Value = Cash.Value + 500
i = 60
end
end
else
Wallet.Countdown.Text = "You get $" ..Income.Value.. " in: " ..i
end
end

It counts down all the way to 1, then it freezes. I tried changing if i == 1 then, but then it stopped at 2. Help? All variables are predefined and working.

1 answer

First: Tab your code.


Second: There's no reason to check for 0 in the loop. The loop stops; that's what 0 means. Put your code after the loop.


You aren't supposed to assign to variables being iterated by for loops; Lua's documentation suggests that it's dangerous to do so -- and it doesn't have to cause any particular effect. Don't do it.

Even in the event that that made sense, you would only have to do it once -- and you would do it either before or after all of the loops, not in each iteration of each inner loop.

Instead, just use a while true do loop around the whole process.


I don't know how you have your code structured, so I don't know how you get MinWage, MedWage, etc. It would probably make more sense to get the wage rate directly, eg..

local classes = {
	NONE = 100,
	MIN = 200,
	MED = 400,
	ADMIN = 600
}

Cash.Value = Cash.Value + classes[ player.WageRate.Value ]

This would replace the 21 lines you currently have, and make it trivial to add new classes of earnings (and avoid four for loops and four if statements)

This discussion is preserved as it was. New answers, comments, and votes are closed.