# Is there a way to generate an array of number that skip counts 0.5 or 3 or any number?

like for example
0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 so on and so on?

Yeah, you can specify an increment, otherwise known as `step` for a third option:
https://www.lua.org/pil/4.3.4.html

``````for i = 0.5 --[[ Start ]], 4.5 --[[ End ]], 0.5 --[[ Step ]] do
print(i)
end
``````

Though you have to be careful with floating point numbers due to how floating points are calculated, they aren’t always precise and you can run into issues.

3 Likes

Thankyou!, I was expecting that maybe there is a math.generate numbers thingy in roblox, I was actually going to use the numbers in an if statement, I just utilized you’re method to my need by adding table.insert

``````local urnumb = 0
while true do
urnumb += .5
print(urnumb)
end``````
1 Like

Here’s an example in case anyone else is wondering how to do this.

``````function letsGenerate(Start, Finish, SkipCount)
local Array = {}
for Number = Start, Finish, SkipCount do
Array[#Array+1] = Number
end
return Array
end
local NumbersArray = letsGenerate(0, 50, 0.5)
for _, Number in pairs(NumbersArray) do
print(Number)
end
``````
1 Like