Im kinda at a loss right now.
Heres the code, there are no errors, the script just loads in an elevator no matter the number
Elevator=math.random(1,50)
if Elevator==1 then
for i,v in pairs(EligibleRooms) do
if not string.find(v.Name,"Elevator") then
table.remove(EligibleRooms,i)
end
end
else
for i,v in pairs(EligibleRooms) do
if string.find(v.Name,"Elevator") then
table.remove(EligibleRooms,i)
end
end
end
All rooms with an elevator are named something along the lines with “Elevator_R_1D” or “Elevator_R_3DLR”
Edit: Been checking a lot with the output and printing, the for loops aren’t detecting the name “Elevator_R_2DLR” at all, and when the number is one, sometimes the loops don’t even remove the rooms without an elevator
1 Like
I don’t see this script loading or parenting any elevator, I just see it removing items from a table, show me a little more context.
This is right after that block of code
ChosenRoom=math.random(1,table.maxn(EligibleRooms))
for i,v in pairs(EligibleRooms) do
if i==ChosenRoom then
ChosenRoom=v
end
end
the chosen room is then cloned and put into the workspace
can I ask what the EligibleRooms
variable does?
Your issues are probably stemming from the fact that you’re modifying a table (using table.remove) while you’re iterating over it. Especially since table.remove shifts the indexes of the other down.
One option would be to be populating another list like RoomsToChoseFrom from Eligible rooms and then use that table in your ChosenRoom logic.
You could also try doing EligibleRooms[i] = nil intead of using table.remove since that should leave the indexes alone. But in general, try not to modify a table as you iterate over it.
Eligiblerooms is a :GetChildren() table of a folder in serverstorage full of rooms that spawn randomly
Did you resolve this issue?
I do think it’s with the indexes changing from table.remove