Whenever this code runs, after a while it returns an error saying: Workspace.cogworld.bomb rain:4: invalid argument #1 to ‘random’ (interval is empty)
here’s my code:
while true do --Loops the script
wait(1)
local children = script.Parent.bombs:GetChildren()
local M = math.random(#children)
droplet = children[M]:Clone()
droplet.Parent = game.Workspace
droplet.Anchored = false
droplet.Transparency = 0
end
At this line, when there are no children present in the bombs object, its going to return nil, and it will be the value of the variable children, then when you call math.random(), it expects a numerical value, which nil isn’t, so do this to make your code safe:-
while true do --Loops the script
wait(1)
local children = script.Parent.bombs:GetChildren()
if(children == nil) then break end --this will terminate your loop, add some other code if you wanna achieve something else.
local M = math.random(#children)
droplet = children[M]:Clone()
droplet.Parent = game.Workspace
droplet.Anchored = false
droplet.Transparency = 0
end