GetChildren() failure

Once again, I’m making yet another game. At this point I should probably just stick with one.
Anyways, I’m attempting to check all the children of a group. However, on the second time (after I clear the group) it shuts down the script because there are no children in the folder.
Here’s the code. The failure is at the GetChildren() line

while wait() do
	local boxes = script.Parent:GetChildren("Box")
	if #boxes >= 12 then
		print("resetting map")
		game.Workspace.failGUIevent:FireAllClients()
		print("sending message...")
		local maps = game.ReplicatedStorage.Maps:GetChildren()
		local map = game.Workspace.Map:GetChildren()
		game.Lighting.Blur.Size = 50
		for i = 1, #map do
			local maptomoveback = map[i]
			maptomoveback.Parent = game.ReplicatedStorage.Maps
		end
		for box = 1, #boxes do
			local b = boxes[box]
			b:Destroy()
		end
		game.Workspace.Failure:Play()
		wait(3)
		game.Workspace.FailTheme:Play()
		wait(16)
		local newmapnum = math.random(1, #maps)
		local newmap = maps[newmapnum]
		newmap.Parent = game.Workspace.Map
		game.Lighting.Blur.Size = 2
		game.Workspace.BoxesDelivered.Value = 0
		game.Workspace.FailTheme:Stop()
		game.Workspace.FailTheme.TimePosition = 0
	end
end

I understand what I need to do, but I don’t know how to go about doing it.

Are you trying to get all the children named Box? You must go through them and place them on a table yourself.

while task.wait() do
	local boxes = {}
	for _,v in pairs(script.Parent:GetChildren()) do
		if v.Name == "Box" then
			table.insert(boxes, v)
		end
	end
	
	if #boxes >= 12 then
		print("resetting map")
		workspace.failGUIevent:FireAllClients()
		print("sending message...")
		local maps = game:GetService("ReplicatedStorage").Maps:GetChildren()
		game:GetService("Lighting").Blur.Size = 50
		
		for _,maptomoveback in pairs(workspace.Map:GetChildren()) do
			maptomoveback.Parent = game:GetService("ReplicatedStorage").Maps
		end
		for _,b in pairs(boxes) do		b:Destroy()		end
		workspace.Failure:Play()
		task.wait(3)
		workspace.FailTheme:Play()
		task.wait(16)
		local newmapnum = math.random(#maps)
		local newmap = maps[newmapnum]
		newmap.Parent = workspace.Map
		game:GetService("Lighting").Blur.Size = 2
		workspace.BoxesDelivered.Value = 0
		workspace.FailTheme:Stop()
		workspace.FailTheme.TimePosition = 0
	end
end