I am trying to create a script in which a list of values in table are references based on the index the percentage value a player chooses. However, for certain indexes, it keeps returning a nil value, and so far I cannot figure out a solution. Would anyone mind taking a look at it and find a possible solution?
local percentage = 0.1
local list = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
while percentage < 1 do
print(list[percentage * 10])
percentage = percentage + 0.1
wait()
end
--for index 3, 8, and 10, the table outputs nil.(list[percentage * 10]) = nil)
print("----------------------------------")
local num = 1
print(list[0.1 * 10])
print(list[0.2 * 10])
print(list[0.3 * 10])
print(list[0.4 * 10])
print(list[0.5 * 10])
print(list[0.6 * 10])
print(list[0.7 * 10])
print(list[0.8 * 10])
print(list[0.9 * 10])
print(list[1 * 10])
--This works perfectly fine, outputting all components of the table.

1 comment
Just tested this. That is very weird. I'd also like to know the cause of this.