Invalid argument #2 to 'random' (interval is empty), how do i fix it?

Whenever the script runs, it displays the error ‘Workspace.rooms.cogworld.bomb rain:5: invalid argument #2 to ‘random’ (interval is empty)’ after a few seconds and stops running. Does anyone know how to fix this?

while true do
	wait(1) 
	local children = script.Parent.bombs:GetChildren()
	if(children == nil) then break end
	local M = math.random(1,#children)
	droplet = children[M]:Clone()
	droplet.Parent = game.Workspace
	droplet.Anchored = false
	droplet.Transparency = 0
end

There must be no children here which creates the interval (1, 0) in your math.random arguments.

:GetChildren() always returns a table, so it can’t be nil. Instead, check like this:

if(#children == 0) then break end

image
there are children in the folder, so I don’t know why it’s doing this

Maybe try printing the children inside the script?

Edit: It is definitely an issue with the children part here. I get the same error message when putting 0 instead of #children. That is the only time I get an error, and :GetChildren() only returns tables with the minimum value being 0. I did this in console:

1 Like

It prints this when it runs:
image

And what if you print #children? Also is this supposed to run when #children == 0 at any point? Like it might work the first few times that #children ~= 0, but after that it will probably break and error. Did it error out when you did this printing?

It’s counting down from the amount of children in the folder, and when it reaches 0, it ends. I don’t know why, because I am obviously cloning the object and not taking it out of the folder.

Nevermind, it’s because the bombs explode when its clone touches it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.