Hi so I have this tier system and the code needs to figure out which tier a player is, more boom power = higher tier, when running the script with 5 boom power it prints tier 9 despite the fact it should be tier 1? can anybody help me know why. I have found that the > and < signs in roblox are very bugy
function figureouttier()
if player.leaderstats.BoomPower.Value <= 200 then
tier = 1
end
if player.leaderstats.BoomPower.Value <= 400 then
tier = 2
end
if player.leaderstats.BoomPower.Value <= 600 then
tier = 3
end
if player.leaderstats.BoomPower.Value <= 800 then
tier = 4
end
if player.leaderstats.BoomPower.Value <= 1000 then
tier = 5
end
if player.leaderstats.BoomPower.Value <= 1200 then
tier = 6
end
if player.leaderstats.BoomPower.Value <= 1400 then
tier = 7
end
if player.leaderstats.BoomPower.Value <= 1600 then
tier = 8
end
if player.leaderstats.BoomPower.Value <= 2000 then
tier = 9
end
print(tier)
end
Put all these if statements in reverse order and it will work.
Itâs happening because the Lua code is interpreted from the top to the bottom, so if BoomPower is 5 it will go through all these if statements and if every condition is satisfied and every part of code associated with that condition makes a change to the tier variable then only the last change will be visible as it will overwrite the previous changes to tier.
This is because it is true for all of your if statements, so it runs your code. You shouldnt be using repeated if statements for this anyway, try doing: tier = math.floor(player.leaderstats.BoomPower.Value / 200)
you are using smaller and equal to <=, but you need to detect another thing
function figureouttier()
if player.leaderstats.BoomPower.Value <= 200 then
tier = 1
end
if player.leaderstats.BoomPower.Value <= 400 and > 200 then
tier = 2
end
if player.leaderstats.BoomPower.Value <= 600 and > 400 then
tier = 3
end
if player.leaderstats.BoomPower.Value <= 800 and > 600 then
tier = 4
end
if player.leaderstats.BoomPower.Value <= 1000 and > 800 then
tier = 5
end
if player.leaderstats.BoomPower.Value <= 1200 and > 1000 then
tier = 6
end
if player.leaderstats.BoomPower.Value <= 1400 and > 1200 then
tier = 7
end
if player.leaderstats.BoomPower.Value <= 1600 and > 1400 then
tier = 8
end
if player.leaderstats.BoomPower.Value <= 2000 then
tier = 9
end
print(tier)
end
Keep in mind that the â>â and â<â signs in Lua are not âvery buggyâ. These symbols are called inequality operators. They allow you to determine if a number is larger than another number or if a number is smaller than another one.
For example, the expression 5 > 4 will be evaluated as true. This is because five is larger than 4. On the other hand, 4 > 5 will be evaluated as false. One trick to remember which symbol means what is to think of them as alligators (as > looks like an alligators mouth when eating). The alligator always wants to eat the larger number of fish, so whatever number the mouth is open toward is the larger number.