Code not working(dont mind my spaghetti code)

Hey I have code to generate an obby but it’s not fully working. Don’t mind my spaghetti code but I think it might be mostly the bottom:

local used = 0
script.Parent.Touched:Connect(function(hit)
	if used == 0 then
		if hit.Parent:FindFirstChild("Humanoid") then
			used = 1
			local name = 1
			local part = Instance.new("Part", workspace)
			part.Name = name
			name += 1
			local genScript = game:GetService("ReplicatedStorage").Generate:Clone()
			genScript.Parent = part
			local rand = 0
			local distance = 0
				rand = math.random(1, 3)
			if rand == 1 then
				if not part.Name == "1" then
					if not workspace:FindFirstChild(name-1).Shape == Enum.PartType.Ball then
						part.Shape = Enum.PartType.Ball
						distance = 24
					else
						part.Shape = Enum.PartType.Cylinder
						distance = 14
					end
				end
			elseif not part.Name == "1" then
				if not workspace:FindFirstChild(name-1).Shape == Enum.PartType.Cylinder then
					part.Shape = Enum.PartType.Cylinder
					distance = 14
				else
					part.Shape = Enum.PartType.Block
					distance = 16
				end
			elseif not part.Name == "1" then
				if not workspace:FindFirstChild(name-1).Shape == Enum.PartType.Block then
					part.Shape = Enum.PartType.Block
					distance = 16
				else
					part.Shape = Enum.PartType.Ball
					distance = 24
				end
			end
				part.Size = Vector3.new(math.random(8, 16), 2, math.random(8, 16))
				part.Anchored = true
				part.CFrame = script.Parent.CFrame:ToWorldSpace(CFrame.new(0, 0, 0)) + CFrame.new(distance, 0, 0)

		end
	end
end)

Please help

You check the same condition twice, only the first one is going to run

Guess that might’ve helped something but from my tests it’s still spawning far away, but continuing after that.