# Unordered for loop

how do i do a for loop except tht it doesnt go 1 by 1 and randomly and doesnt repeat itself?

Can you give an example of what you mean?

2 Likes
``````for i,v in pairs(table) do
corountine.wrap(function()
-- code
end)()
end
``````

this? it will ignore the wait() and all and continue the loop, basically performs the code but doesn’t wait for it to end to perform the next one. I don’t know what do you mean by randomly and doesn’t repeat itself.

1 Like

i mean like i will be randomly picked and i wont repeat

Can you send us your script? I don’t really get what you mean. For loops don’t repeat anyway

1 Like

Do you mean

``````local tbl = {}
for i = math.random(),math.random() do
if not table.find(tbl, i) then
table.insert(tbl, i)
print("Random index is:"..i)
end
end
``````

yes smthg similar to tht but `i` shouldnt repeat itself

And for what purpose do you need it?
Chance system?

Then just use math.random(), if you’re only running it once then there’s no need for a for loop.

For example,

``````local randomNumber = math.random(1,10)

if randomNumber = 6 then
--do something
end
``````
1 Like

sort of its like for randomly going thru a list of floors like not 1 by 1 just randomly

well there is need for a for loop since i have to go thru all floors but just not in order

Oh okay. You’d need to make a table for this. Use :GetChildren() on the directory in which your floors are stored and add each individual floor to a table. Then randomize the table.

``````
local FloorFolder = game.ReplicatedStorage.FloorFolder:GetChildren()
local table = {}

for i = 1,#FloorFolder do
table.insert(table,1,i.Name)
end

--This should give you a table with each floor in it.

--You should now shuffle the table``````

Check out my edited post it should not repeat.

how do i do that as far as i know pairs does it in order