For loop not running

The placeEgg function wasn’t working so I debugged it with print and found out that the for loop wasn’t running. There are no errors and print("a") works fine, can someone help me make the for loop run?

local function placeEgg(instance)
	print("make")
	local egg = instance:Clone()
	egg.Parent = workspace
	
	local x = math.random(-803, 292)
	local z = math.random(-1042, 45)
	egg.Position = Vector3.new(x, 32.02, z)
	egg.CanCollide = false
	egg.Anchored = true
	
end


while total_eggs <= 100 and wait(3) do
	total_eggs += 1
	local num = math.random(0,10000)
	print("a")
	for i,v in ipairs(eggs) do
		print("for loop")
		if v["Rarity"] <= num then
			print("found")
			placeEgg(v["Instance"])
			break
		end
	end
	
end
1 Like

Try switching the ipairs for pairs

2 Likes

Shouldnt be the issue, eggs is a table

I’d recommend trying it, someone else had the same issue and it fixed it for them. Also ipairs, instead of returning an error, will just not run so it’s not always obvious that it doesn’t work.

Because if there’s no error then techincally nothing else should be causing it

What’s the error in your script? Where’s the table for “eggs”?

To add another thing; ipairs will stop if it runs into a nil value, which could also be causing the issue

try printing “eggs” and see what comes up in your output, I would assume it would be nil